简体   繁体   中英

menuitemclick event firing on Master but not child page

I have a menu on a master page with the following:

<asp:SiteMapDataSource runat="server" ID="SiteMapDataSource" ShowStartingNode="false" /> 

<asp:Menu ID="mnuMain1" runat="server" RenderingMode="List" StaticSelectedStyle-CssClass="selected" IncludeStyleBlock="false" DataSourceID="siteMapDataSource" MaximumDynamicDisplayLevels="0" OnMenuItemClick="mnuMain1_MenuItemClick">
         <DataBindings>
            <asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
         </DataBindings>
</asp:Menu>

Code in .Master.cs file:

protected void mnuMain1_MenuItemClick(object sender, MenuEventArgs e)
    {
        MenuItem mnu = e.Item;
    }

I have created a webpage that inherits from the master - this asks the user to populate a Location field. When the user clicks on a menu item it needs to check the Location field has a value before proceeding. I have a MenuItemClick eventhandler declared in the code. The MenuItemClick event fires on the Master but not on the inherited page.

Have I missed something really obvious?

AutoEventWireup doesn't work on the page that uses the master page. You have to explicitly bind the event receiver. You can do this by exposing the control as a properly on the master page and then binding to the event in the child page.

Check out this article: http://www.codeproject.com/Articles/36055/Interaction-Between-Content-Page-and-Master-Page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM