简体   繁体   English

asp:Menu 在不同控件执行部分 AJAX 回发后停止工作

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

This issue occurs in ASP.NET 4.6 and I've seen a few similar posts, but they usually referred not to the same control (built-in here) or ended up with a conclusion "just use a different/external control here: html link", which is not really an option for me.这个问题出现在 ASP.NET 4.6 中,我看过一些类似的帖子,但他们通常提到的不是同一个控件(内置于此处)或最终得出结论“只需在此处使用不同的/外部控件:html链接”,这对我来说并不是一个真正的选择。

First, some code首先,一些代码

Site.Master站点管理员

 <div id="HeaderProper">
    <div id="HeaderProperTitle">
        <asp:Menu ID="HeaderProperMenu" runat="server" DataSourceID="HeaderProperSiteMap" Orientation="Horizontal"  
            BackColor="#ff2400" 
            RenderingMode="List"
            StaticEnableDefaultPopOutImage="false"
            StaticDisplayLevels="2"
            StaticHoverStyle-BackColor="#000000"
            StaticMenuItemStyle-HorizontalPadding="15px"
            StaticMenuItemStyle-Height="42px"
            DynamicHoverStyle-BackColor="#000000" 
            DynamicMenuItemStyle-HorizontalPadding="5px"
            DynamicMenuItemStyle-BackColor="#ff2400"
            DynamicMenuItemStyle-Font-Size="24px"/>
<asp:SiteMapDataSource ID="HeaderProperSiteMap" runat="server" />
</div>

SomePage.aspx SomePage.aspx

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h1>Complete List</h1>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div class="SortOrderSelection">
                    Sort by
                    <asp:DropDownList ID="cbxSortBy" runat="server" AutoPostBack="true"
                        OnSelectedIndexChanged="cbxSortBy_SelectedIndexChanged" />
                </div>
                <asp:Panel ID="SortedList" CssClass="top-margin five-columns" runat="server" />
                <asp:Panel ID="Summary" CssClass="top-margin" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>

How to reproduce: Choose an item in the DropDownList, which causes partial postback.如何重现:在 DropDownList 中选择一个项目,这会导致部分回发。 The menu then stops working, that is - the drop down/hover menu doesn't open, but the first level links seem to be functional.然后菜单停止工作,即 - 下拉/悬停菜单未打开,但第一级链接似乎可以正常工作。 Refreshing the whole page fixes the problems (duh?).刷新整个页面可以解决问题(呃?)。

And, contrary to what I've found: 1) Menu is NOT inside an UpdatePanel, which I acknowledge is unsupported solution 2) Menu works fine when RenderingMode is set to Table, but generates a very ugly html code, which I would like to avoid.而且,与我发现的相反:1) 菜单不在 UpdatePanel 内,我承认这是不受支持的解决方案 2) 当 RenderingMode 设置为 Table 时菜单工作正常,但会生成一个非常难看的 html 代码,我想避免。 Not mentioning additional quirks in margins that have to be adjusted with ugly fixes.没有提到必须用丑陋的修复来调整边距中的额外怪癖。 3) I tried setting z-index: 1000...0 !important as suggested by some sources (on most menu related styles), but to no avail. 3)我尝试设置 z-index: 1000...0 !important 按照某些来源的建议(在大多数与菜单相关的样式上),但无济于事。

I would be grateful for any suggestions how this can be resolved while still using asp:Menu control in List rendering mode, possibly with as least intervention as possible.对于如何在列表呈现模式下仍然使用 asp:Menu 控件的同时解决此问题的任何建议,我将不胜感激,可能需要尽可能少的干预。 My point here is to use built-in functionality and keep the code clean from unnecessary JS, jQuery (if possible at all; otherwise I'd rather open a Connect case for this issue).我的观点是使用内置功能并保持代码干净,避免不必要的 JS、jQuery(如果可能的话;否则我宁愿为此问题打开一个 Connect 案例)。 Thank you in advance.先感谢您。

Putting your menu into an update panel should work because it will indicate to the server to update it after the postback.将菜单放入更新面板应该可以工作,因为它会指示服务器在回发后更新它。 Without this, any repost can create the risk of losing some events in your element.如果没有这个,任何重新发布都可能造成丢失元素中某些事件的风险。 Refreshing works because you are refreshing the whole page and not only some element of it.刷新之所以有效,是因为您正在刷新整个页面,而不仅仅是其中的某些元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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