简体   繁体   中英

asp submenu items not displaying after partial postback

I have a asp:Menu object that dynamically builds a dropdown style menu from a web.sitemap file. The menu works fine until a partial postback is fired from within an UpdatePanel.

After the postback, the dropdown feature no longer works (the html code for the objects is still visible when you inspect the page). The first level items are still clickable, but those with subitems do not expand like they should.

I found these older posts with the same issue, but they don't really have solutions.

ASP.Net submenu not show after postback

asp menu not working after partial postback

How do I get my menus working again after a partial postback?

Site.Master

        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
            <asp:Menu ID="NavMenu" StaticMenuStyle-CssClass="nav navbar-nav" DynamicMenuStyle-CssClass="dropdown-menu" runat="server" 
                    EnableViewState="false" RenderingMode="List" 
                    StaticEnableDefaultPopOutImage="false"
                    IncludeStyleBlock="false" Orientation="Horizontal"
                    DataSourceID="SiteMapDataSource1" OnMenuItemDataBound="NavMenu_MenuItemDataBound" ></asp:Menu>
                <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
                </ul>
            <ul class="nav navbar-nav  navbar-right">
                <li class="navbar-text">Welcome <asp:label runat="server" id="FullName">User</asp:label></li>
                <li><asp:Button ID="LogoutBtn" runat="server" OnClick="btnLogout_Click" CssClass="Logout-button" Text="Logout" /></li>
            </ul>
        </div>

Any page with an update panel

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ListBox ID="ListBox1" runat="server" Rows="15" SelectionMode="Single" OnSelectedIndexChanged="SelectedIndexChanged" AutoPostBack="true"></asp:ListBox>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

Following the advice from an answer on a similar question (link below) - wrapping the ul menu structure in an asp:UpdatePanel fixes the issue with the menu not displaying correctly after partial postbacks.

Not sure if this is really the best way to fix the issue, but it does work!

asp:Menu stops working after a different control performs partial AJAX postback

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