javascript 如何从 ASP.NET 中的 MenuItem 调用 onClick 事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11396321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:02:18  来源:igfitidea点击:

How do you call an onClick event from a MenuItem in ASP.NET?

javascriptasp.netcode-behind

提问by Learner

How do you call an onclickevent from MenuItemsince there is no OnClickproperty for MenuItemin ASP.NET?

由于在 ASP.NET 中没有属性,您如何调用onclick事件?MenuItemOnClickMenuItem

Using NavigateUrlwe can navaigate to a particular url but once I click on MenuItemit should trigger an event.

使用NavigateUrl我们可以导航到特定的 url 但一旦我点击MenuItem它应该触发一个事件。

回答by Ashwin Singh

Menu has MenuItem.MenuItemClickevent, you can use that to do whatever you wanted with onclick.

菜单有MenuItem.MenuItemClick事件,你可以用它来做任何你想做的事情onclick

回答by Joe

You can use the Menu.MenuItemClickevent of the Menu that contains your menu item:

您可以使用Menu.MenuItemClick包含您的菜单项的 Menu 事件:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.menuitemclick.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.menuitemclick.aspx

<asp:Menu runat="server" ID="MyMenu" onmenuitemclick="MyMenu_MenuItemClick" ... >
    ...
</asp:Menu>

Clicking on any menu item that does not have the NavigateUrlproperty set will cause the page to be postback and the Menu.MenuItemClickevent handler to be executed.

单击没有NavigateUrl设置属性的任何菜单项将导致页面回发并执行Menu.MenuItemClick事件处理程序。