Does C# have a Handles keyword?

寵の児 提交于 2019-12-01 18:25:34

Nope. You will have to wire up the event like this

Menu1.MenuItemClick += Menu1_MenuItemClick;

Its pretty easy to setup handlers in C#. In my option much easier than VB.Net. You'll need to make sure the handler gets setup early enough in the page to get fired off. Just type in the object name (Menu1) . (the name of the event) the "+=" and hit tab twice. Visual Stuido will generate everything for you.

You have to assign the events yourself using the += syntax.

Generally this goes right in the markup.

<asp:Menu ID="Menu1" runat="server" onmenuitemclick="Menu1_MenuItemClick"></asp:Menu>

and in the codebehind it looks like

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{

}

You can generate all of this in Visual Studio from the designer. Select the menu control, go to the properties window (f4), view the events list (the lightning bolt) and double click the event name.

You can also subscribe an event handler manually with += but you have to do it every time the page loads.

If you don't mind doing so, you can always set the AutoEventWireUp to "true". Then C# will automatically bind event handlers with "VB" names.

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