简体   繁体   English

为什么在不相关的更新面板刷新中,ASP.NET菜单控件中出现随机的“事件”是未定义的错误?

[英]Why am I getting a random 'Event' is undefined error in ASP.NET menu control on an unrelated Update Panel refresh?

This has been plaguing me for a while. 这一直困扰着我一段时间。

I have a page in my app that is a content page. 我的应用程序中有一个内容页面。 The asp.net master page has a Menu Control. asp.net主页具有菜单控件。

This Menu Control is a user control that contains an object, and all of the event handling to bind the menu to various sitemap files based on the user. 此菜单控件是一个用户控件,其中包含一个对象以及所有事件处理,以根据用户将菜单绑定到各种站点地图文件。

The content page has a form with various forms and grids with update panels for putting together a complicated object. 内容页面具有一个表单,该表单具有各种表单以及带有用于将复杂对象组合在一起的更新面板的网格。 When completed the user submits the form and it should create the new object. 完成后,用户将提交表单,表单应创建新对象。

The problem is when updating one of the gridviews or submitting the form, I get an 'Event' is undefined error from a ScriptResource.axd file and it looks like the code is from the ASP menu control. 问题是,当更新一个gridviews或提交表单时,我从ScriptResource.axd文件中得到“事件”是未定义的错误,并且看起来该代码来自ASP菜单控件。 Here is the context in which the error occurs. 这是发生错误的上下文。 It breaks right after Menu_ClearInterval(): 它在Menu_ClearInterval()之后立即中断:

function Menu_HideItems(items) {
if (document.body.__oldOnClick) {
    document.body.onclick = document.body.__oldOnClick;
    document.body.__oldOnClick = null;
}
Menu_ClearInterval();

it breaks on this line: 它在此行中断:

if (!items || ((typeof(items.tagName) == "undefined") && (items instanceof Event))) {

    items = __rootMenuItem;
}
var table = items;
if ((typeof(table) == "undefined") || (table == null) || !table.tagName || (table.tagName.toLowerCase() != "table")) {
    table = WebForm_GetElementByTagName(table, "TABLE");
}
if ((typeof(table) == "undefined") || (table == null) || !table.tagName || (table.tagName.toLowerCase() != "table")) {
    return;
}
... rest of function
}

The context for the function has an items variable which looks like it contains event data, eg: 该函数的上下文有一个items变量,看起来像它包含事件数据,例如:

{ type: "click", target: { id: "btnAddItem" }, Methods: stopPropagation() }

Not sure if it matters. 不确定是否重要。 All other locals are undefined at this time. 目前所有其他本地人都未定义。

Has anyone had a problem like this before? 以前有人遇到过这样的问题吗? Any help is appreciated. 任何帮助表示赞赏。 This is a production problem and short of rewriting this to use pure jquery and ajax (not a quick fix) I'm not sure what else to do. 这是一个生产问题,缺少使用纯jquery和ajax重写这一点的方法(不是快速解决方案),我不确定该怎么做。

Thanks in advance for your help! 在此先感谢您的帮助!

EDIT: To be clear, I'm not sure if this is the menu control causing the error, just that the surrounding code in the ScriptResource.axd file looks like menu code. 编辑:要清楚,我不确定这是否是导致错误的菜单控件,只是ScriptResource.axd文件中的周围代码看起来像菜单代码。

EDIT2 (Reproducable!): Ok, more details. EDIT2(可复制!):好的,更多详细信息。 This error occurs if I hover over the menu control after the page loads. 如果在页面加载后将鼠标悬停在菜单控件上,则会发生此错误。 If I don't hover, it won't occur and everything works fine. 如果我不悬停,它将不会发生,并且一切正常。 If I hover, it will error on the next ajax post. 如果我将鼠标悬停,它将在下一个ajax发布中出错。 This page helped me figure that much out. 该页面帮助我找到了很多东西。 Thoughts? 有什么想法吗?

Menu Markup: 菜单标记:

  <asp:Menu ID="mainMenu" runat="server" Orientation="Horizontal" OnMenuItemDataBound="mainMenu_MenuItemDataBound">
    <StaticMenuStyle CssClass="menu" />
    <StaticMenuItemStyle CssClass="menuItem" />
    <StaticSelectedStyle CssClass="menuSelected" />
    <StaticHoverStyle CssClass="menuHover" />     
    <DynamicMenuItemStyle CssClass="menuItem dMenuItem" />
    <DynamicSelectedStyle CssClass="menuSelected dMenuSelected" />
    <DynamicHoverStyle CssClass="menuHover dMenuHover" />            
    <LevelSubMenuStyles>
        <asp:SubMenuStyle CssClass="menu" />
        <asp:SubMenuStyle CssClass="subMenu" BackColor="#DDDDDD" />
    </LevelSubMenuStyles>
    <LevelMenuItemStyles>
        <asp:MenuItemStyle CssClass="menuItem" />
        <asp:MenuItemStyle CssClass="subMenuItem" />
    </LevelMenuItemStyles>
    <DataBindings> 
        <asp:MenuItemBinding DataMember="siteMapNode" 
             TextField="title" NavigateUrlField="url"  /> 
    </DataBindings> 
</asp:Menu>

Adding it to a page where a menu resides makes the javascript error go away. 将其添加到菜单所在的页面可使javascript错误消失。

var oldMenu_HideItems = Menu_HideItems;   
if(oldMenu_HideItems)
{
    Menu_HideItems = function(items)
    {
        try
          {
            return oldMenu_HideItems(items);
          }
        catch(err)
          {

          }
    }
} 

Source at http://forums.asp.net/t/1059668.aspx 来源http://forums.asp.net/t/1059668.aspx

I would try to contain each control in it's own UpdatePanel with UpdateMode=Conditional and explicitly Update specific content when needed. 我将尝试使用UpdateMode=Conditional将每个控件包含在其自己的UpdatePanel ,并在需要时显式Update特定内容。 If you need the entire page reloaded, go ahead and do a hard refresh to get the state back in order. 如果需要重新加载整个页面,请继续进行硬刷新以使状态恢复原状。

I was not able to come up with a solution to this, so I ended up going with a different menu. 我无法为此提出解决方案,因此最终选择了另一个菜单。

The Queness Drop Down Menu was the simplest to implement with similar functionality and style. Queness下拉菜单是最简单的,具有相似功能和样式的实现。

The solution is easy: the Event object from ScriptResource.axd file is overwritten by another object with the same name, somewhere in your javascript files. 解决方案很简单:ScriptResource.axd文件中的Event对象被javascript文件中某个位置的另一个具有相同名称的对象覆盖。 The same issue I had, and solve it with this solution. 我遇到了同样的问题,并使用此解决方案解决了。

Best regards. 最好的祝福。

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

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