如何定义母版页控件的事件句柄?

时间:2015-03-19 13:23:15

标签: c# asp.net event-handling

代码背后:

Menu masterpagemenu = (Menu)this.Master.FindControl("NavigationMenuAdmin");
masterpagemenu.MenuItemClick += new EventHandler(masterpagemenu_Click);

给出错误:

 Cannot implicitly Convert type System.EventHandler to System.Web.UI.WebControls.MenuEventHandler

为什么会这样?

1 个答案:

答案 0 :(得分:0)

您收到类型转换错误。它告诉您,您正在为MenuItemClick分配错误类型的事件。 MenuItemClick期待MenuEventHandler,请尝试以下方式:

masterpagemenu.MenuItemClick += new MenuEventHandler(masterpagemenu_Click);