This is a pretty straight forward request, but I haven't succeeded yet. I am upgrading an older menu to 10.3, and some of the navigation events are actually javascript calls to pop up a new window. Unfortunately, I cannot simply put the javascript in the NavigateURL because it creates an <a href=java> which will create the popup but also navigate the page into oblivion.
Is there a way to make a menu item execute a javascript command without navigating the page?
Hi MrTwenty8,
can you be more specific. Do you want to execute JavaScript code when item is clicked, or?
And if no please provide some sample to us
Thanks
Hi,
Yes, I wish to execute a javascript function when a specific menu item is clicked.
Hi you have to hook to itemClicked event and do your logic into the JS. If you wish to execute code on particular item, you have to check if the clicked node is the one you want. The comparison could be made by some value - i.e. id of the node or whatever you've put in it.
i.e.
<ig:WebDataMenu ID="WebDataMenuSample" runat="server">
<
ClientEvents ItemClick="itemClick" />
</
ig:WebDataMenu>
script language="javascript" type="text/javascript">
function itemClick(menu, eventArgs) {
//Do your logic here
}
script>
Right, ok.
I was hoping for more of a code-behind solution. This menu is generated from the results of several SQL statements in the codebehind of the control. This solution would require the client side code to know the url to every popup I want to create, which adds complexity that really shouldn't be needed. I will read up on ClientEvents, maybe there is a smarter way to do it, but I don't see it right now.
Is there now way in the code behind to specify the OnClick attribute of the hyperlink generated in the menu?
I've got the same problem today.
To solve it, I reproduce the same action that navigateUrl produce when nothing is specified.
string javascriptAction = "BLOCKED SCRIPTwindow.open('test.aspx')";
newItem.NavigateUrl = javascriptAction + (";void(0);");
and now my main window stay as it should be
best regards
jf
the "BLOCKED SCRIPT" should be "j a v a s c r i p t :" without all spaces