- Home
- Forum
- ASP.NET Web Forms
- Context Menu and Default Button Response Questions
Context Menu and Default Button Response Questions
Thanks for using Syncfusion Products.
Please find the response.
Based on your requirement we have created the sample. Please find the sample as follows,
Sample: aspsample_(2).zip
Query:#1 I have a grid that I do not want to allow editing or deleting on, If I enable the context menu, it provides options that allow this to happen. How can I remove those items from the context menu so that it shows Add as the only default item?
If you want to display the selected items in context menu, we suggest you to use the “contextMenuItems” property in the contextMenuSettings. It will show the mentioned items only in context menu of Grid and please refer the following code snippet.
<ej:Grid ID="FlatGrid" runat="server" AllowPaging="true"> <ContextMenuSettings EnableContextMenu="true" ContextMenuItems="Add Record"> </ContextMenuSettings> |
Could you please refer the online documentation for more information in the following link.
Documentation: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#contextMenuSettings
Query:#2 I'd also like to change the functionality of add (both the context menu and the add button) to open a dialog control that I have built into a wizard. How can I override the default options for this?
The default behavior of the Toolbar Add button can be overridden by using the ToolbarClick event in Grid and the ContextMenu item behavior can be overidden by using the ContextClick event in Grid. Please find the below code snippet.
<ej:Grid ID="FlatGrid" runat="server" AllowPaging="true"> <ClientSideEvents ToolbarClick="onToolBarClick" ContextClick="onContextClick"/> <script type="text/javascript"> function onToolBarClick(args) { if (args.itemName == "Add") { var obj = $("#MainContent_FlatGrid").ejGrid("instance"); args.cancel = true; // prevent default behavior obj._startAdd(); // you can use the built in wizard here } } function onContextClick(args) { if (args.text == "Add Record") { var obj = $("#MainContent_FlatGrid").ejGrid("instance"); args.cancel = true; // prevent default behavior obj._startAdd(); // you can use the built in wizard here } } |
The default functions are prevented by setting true to the args.cancel function and you can override the method after preventing the default functions to the item. Please refer the documentation for further details.
Documentation for toolbarclick: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#event:toolBarClick
http://help.syncfusion.com/ug/js/index.html#!Documents/toolbar1.htm
Documentation for ContextClick: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#event:contextClick
Please let us know if you have any queries.
Regards,
Balaji Marimuthu
Sorry about the inconvenience caused.
We would like to let you know that we have prevented the default function of Add Record in ToolBarClick and ContextClick client side events. So we have provided the js document online link for your reference.
And the Default function of the toolbar and context menu will be disabled by setting true to the args.cancel function. So the default behavior of the add record will be disabled in the toolbar and context menu.
ej:Grid ID="FlatGrid" runat="server" AllowPaging="true"> <ClientSideEvents ToolbarClick="onToolBarClick" ContextClick="onContextClick"/> <script type="text/javascript"> function onToolBarClick(args) { if (args.itemName == "Add") { // for add record var obj = $("#MainContent_FlatGrid").ejGrid("instance"); args.cancel = true; // prevent default behavior // you can use the built in wizard here } } function onContextClick(args) { if (args.text == "Add Record") { // for add record var obj = $("#MainContent_FlatGrid").ejGrid("instance"); args.cancel = true; // prevent default behavior // you can use the built in wizard here } |
And you can use your own method, after the default behavior is get disabled. We have used the startAdd method for example only, could you please replace your code instead of calling startAdd method.
If the above solution does not meet your requirement, could you please share us your controller and view file that will be helpful to provide better solution ASAP.
Please let us know if you require further assistance on this.
Regards,
Balaji Marimuthu
function onDialogClose(args) { alert("close fired"); $("#dlgAddCRMA").ejDialog({ enabled: false }); OnSuccess(); } function openWizard() { alert("wizard fired"); $("#dlgAddCRMA").ejDialog({ enabled: true }); } function onToolbarClick(args) { if (args.itemName == "Add") { alert('toolbar fired'); args.Cancel = true; var obj = $("#mainContent_gridDashboard").ejGrid("instance"); if (null == obj) alert('object NULL'); else { alert('object NOT NULL'); openWizard(); } //obj._startAdd(); } }
Paul
function onToolbarClick(args) { if (args.itemName == "Add") { args.cancel = true; var obj = $("#mainContent_gridDashboard").ejGrid("instance"); $("#mainContent_dlgAddCRMA").ejDialog({ enabled: true }); alert("add fire complete"); //obj._startAdd(); } }
Paul
Thanks for the update.
We have modified your sample based on your requirement. Please refer the below code snippet.
<ej:Dialog ID="dlgAddCRMA" Width="550" runat="server" ShowOnInit="false"/> <script type="text/javascript"> function openWizard() { alert("wizard fired"); $("#MainContent_dlgAddCRMA").ejDialog({ enabled: true, title:"built in wizard" }); } function onToolBarClick(args) { if (args.itemName == "Add") { alert('toolbar fired'); args.cancel = true; //prevent the default behavior $("#MainContent_dlgAddCRMA").data("ejDialog") !== undefined && $("#MainContent_dlgAddCRMA").ejDialog("destroy"); //destroy the dialog if element is created var obj = $("#MainContent_FlatGrid").ejGrid("instance"); if (null == obj) alert('object NULL'); else { alert('object NOT NULL'); openWizard(); // render the dialog } //obj._startAdd(); } } </script> |
We would like to let you know that, we need to destroy the dialog element if it already created. Because, it will not appear the element properly for the second time. So when button is clicked, the dialog is not appeared in proper way.
For your convenience we have attached the sample: aspsample.zip
If the above solution does not meet your requirement, please modify the provided sample to issue reproducible, which will be helpful to provide better solution at the earliest.
Please let me know if you have any queries.
Regards,
Balaji Marimuthu
Paul
Attachment: aspsample2_8f62613e.zip
We were unable to reproduce reported issue to trigger the events for button with the shared sample. We have prepared a video to depict the behavior of button click event with the shared sample that works fine at our end. Could you please describe your query in detail and provide us the procedure to reproduce the issue reported with button click post back action? This will help us to provide you an appropriate solution.
Sample video download link : http://www.syncfusion.com/downloads/support/forum/118885/f118885-1379307712.zip
Please let us know if you have any questions.
Regards,
Ezhil S
Attachment: 20150504_93315_f3b97adc.zip
Thanks for the update.
We are now able to reproduce the issue with triggering events for button control. The issue is because you have destroyed the Dialog which created on click event of the add button and context menu item in the grid. Destroy method will completely remove the control model and unwire the events in the Dialog control. So that you will not be able to trigger the events after destroying the control.
Modified code snippet:
<code>
[Script]
function onToolBarClick(args) {
if (args.itemName == "Add") {
alert('toolbar fired');
args.cancel = true; //prevent the default behavior
// destroy the dialog removed
var obj = $("#<%=gridDashboard.ClientID%>").ejGrid("instance");
if (null == obj)
alert('object NULL');
else {
alert('object NOT NULL');
openWizard(); // render the dialog
}
//obj._startAdd();
}
}
</code>
Please find the modified sample from the link below:
http://www.syncfusion.com/downloads/support/forum/118885/aspsample-651547776.zip
Could you please let us know why you have tried to destroy the dialog content ? so that we can alternate solution instead of destroying the dialog content.
Please let us know if you have any other queries.
Regards,
Ezhil S
Paul
Thanks for your update.
We have prepared a sample based on the given scenario with a Dialog and multiple panes in it. We have cleared the values using the Cancel button click in the code behind and achieved the requested behavior on navigating throw the Dialog panes using Button Click event.
Please download the sample prepared from the link below:
http://www.syncfusion.com/downloads/support/forum/118885/aspsample_modified851329976.zip
Please let us know if you have any other queries.
Regards,
Ezhil S
<asp:Panel ID="pnlCustomerInformation" runat="server"> <div style="float: left"> <table> <tr> <td> <h2>Customer Information</h2> </td> </tr> <tr> <td>Company Name:</td> <td> <asp:TextBox ID="txtCompanyName" runat="server"></asp:TextBox> </td> </tr> <tr> <td>First Name:</td> <td> <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox> </td> </tr> <tr> <td>Last Name:</td> <td> <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox> </td> </tr> <tr> <td>Phone Number:</td> <td> <asp:TextBox ID="txtPhoneNumber" runat="server" TextMode="Phone"></asp:TextBox> </td> </tr> <tr> <td>Email Address:</td> <td> <asp:TextBox ID="txtEmailAddress" runat="server" TextMode="Email"></asp:TextBox> </td> </tr> </table> </div> <div style="float: right"> <table> <tr> <td> <h2>Address Information</h2> </td> </tr> <tr> <td>Address 1:</td> <td> <asp:TextBox ID="txtAddress1" runat="server"></asp:TextBox> </td> </tr> <tr> <td>Address 2:</td> <td> <asp:TextBox ID="txtAddress2" runat="server"></asp:TextBox> </td> </tr> <tr> <td>City:</td> <td> <asp:TextBox ID="txtCity" runat="server"></asp:TextBox> </td> </tr> <tr> <td>State:</td> <td> <asp:TextBox ID="txtState" runat="server"></asp:TextBox> </td> </tr> <tr> <td>ZipCode:</td> <td> <asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox> </td> </tr> <tr> <td>Country</td> <td> <asp:DropDownList ID="ddlCountry" runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"></asp:DropDownList> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="btnCancelStep1" runat="server" Text="Cancel" OnClick="Cancel_Click" /> <asp:Button ID="btnNextStep1" runat="server" Text="Next" OnClick="btnNextStep1_Click" /> </td> </tr> </table> </div> </asp:Panel> <asp:Panel ID="pnlPartInformation" runat="server" Visible="false"> <table> <tr> <td> <h2>RMA Information</h2> </td> </tr> <tr> <td>Distributor:</td> <td> <asp:DropDownList ID="ddlDistributors" runat="server"></asp:DropDownList> </td> </tr> <tr> <td>Part SKU:</td> <td> <asp:DropDownList ID="ddlPartList" runat="server"></asp:DropDownList> </td> </tr> <tr> <td>Serial Number:</td> <td> <asp:TextBox ID="txtSerialNumber" runat="server"></asp:TextBox> </td> </tr> <tr> <td>Service Request Number:</td> <td> <asp:TextBox ID="txtSRNumber" runat="server"></asp:TextBox> </td> </tr> <tr> <td>Problem Description:</td> <td> <asp:TextBox ID="txtProblemDescription" runat="server" MaxLength="50" TextMode="MultiLine" Rows="4"></asp:TextBox> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="btnBackStep2" runat="server" Text="Back" OnClick="btnBackStep2_Click" /> <asp:Button ID="btnCancelStep2" runat="server" Text="Cancel" OnClick="Cancel_Click" /> <asp:Button ID="btnNextStep2" runat="server" Text="Next" OnClick="btnNextStep2_Click" /> </td> </tr> </table> </asp:Panel>
Thanks for your update.
We have modified the sample using ASP Panels to clear the values on cancel button click and navigating through the wizard inside the Dialog control. Could you please let us know whether the suggested solution works at your end? So that we can provide you alternative solution.
Modified sample with shared code can be downloaded from link below:
http://www.syncfusion.com/downloads/support/forum/118885/aspsample174297424.zip
Please let us know if you have any other queries.
Regards,
Ezhil S
Paul
Thanks for the update.
In order to achieve this behavior we have already logged a defect as per the forum below,
https://www.syncfusion.com/forums/118886/close-of-the-dialog-control-fire-asp-net-function
We will modify the shared sample along with the fix as per your requirement. Please log on to our support website to track the status of this defect in the incident has been created under your account check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
Please let us know if you have any other queries.
Regards,
Ezhil S
- 23 Replies
- 3 Participants
-
PY Paul Yanzick
- Apr 20, 2015 12:31 AM UTC
- May 19, 2015 11:39 AM UTC