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

☆樱花仙子☆ 提交于 2019-12-13 04:16:24

问题


How do you call an onclick event from MenuItem since there is no OnClick property for MenuItem in ASP.NET?

Using NavigateUrl we can navaigate to a particular url but once I click on MenuItem it should trigger an event.


回答1:


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




回答2:


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

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 NavigateUrl property set will cause the page to be postback and the Menu.MenuItemClick event handler to be executed.



来源:https://stackoverflow.com/questions/11396321/how-do-you-call-an-onclick-event-from-a-menuitem-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!