ASP.Net submenu not show after postback

2019-09-01 10:18发布

问题:

I has use ASP.Net menu control in master page. And I wrap the Maincontent using update panel. When postback is happen, the sub menu in master page not showing when mouse over. I need click again the menu then mouseover the menu the sub menu only show.

Master page

        <div class="float-right">                
            <nav>
                <asp:Menu ID="mne" runat="server" Orientation="Horizontal" Font-Names="Arial, Verdana, Tahoma" 
                    OnMenuItemClick="mne_MenuItemClick"  StaticEnableDefaultPopOutImage="false" Width="510px" 
                    DynamicHorizontalOffset="20" StaticSubMenuIndent="250px" TabIndex="1" >
                    <LevelMenuItemStyles>
                        <asp:MenuItemStyle CssClass="level1" HorizontalPadding="10px" />
                    </LevelMenuItemStyles>
                    <StaticMenuStyle  />
                    <DynamicMenuStyle  />
                    <StaticHoverStyle BackColor="Wheat" />
                    <DynamicHoverStyle BackColor="Gray" ForeColor="White" />
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home" 
                           Value="Home"></asp:MenuItem>
                        <asp:MenuItem Text="Management" Value="Management"
                           ToolTip="Management">
                            <asp:MenuItem Text="Edit" Value="Edit" ToolTip="Edit 
                                NavigateUrl="~/Edit.aspx">
                            </asp:MenuItem>
                        </asp:MenuItem>                           
                        <asp:MenuItem Text="Logout" Value="Logout"></asp:MenuItem>
                    </Items>
                </asp:Menu>
            </nav>
        </div>
    </div>
</header>

Edit.aspx

<asp:DropDownList ID="Country" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Country_SelectedIndexChanged">
                    </asp:DropDownList>

After the drop down list postback, mouseover the menu, the submenu not showing. I need click on the menu then mouseover the submenu will display.
Anything is go wrong? Please help

回答1:

I've also been experiencing this intermittently, and none of the other suggestions worked for me. I eventually decided to rem out every line of server-side code and then un-rem them section by section until I discovered what was causing it.

Turns out that it was as a result of server-side JavaScript injection using the ClientScript.RegisterStartupScript(...) method. In certain cases, the client-side objects referred to in the injected JavaScript were not visible at the time the script was injected. Others have hinted at page life-cycle being the root cause of this problem, and this would bear it out.

Once I'd discovered this, I was able to fix it quite easily by making sure that the script checked for visibility of document elements before referencing them. The surprising thing was that, despite having JavaScript warnings enabled, this did not generate any client-side errors.



回答2:

Disable postback of root or parent menu:

MenuItem mnu = new MenuItem();
// if mnu has sub item(s)
mnu.Selectable = false;

this option is more useful when application opened by a mobile device.