id=“end”的 div 母版页中断 .NET 验证
快速信息:我正在使用最新版本的 .NET 2.0,以下是我为重现错误而编写的精简测试页。
不包括标头位(没有包含/内联 css 或javascript) 我的内容页面如下所示:
<asp:Content ID="Content1" ContentPlaceHolderID="cphMain" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:TextBox ID="txtStuff" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtStuff" Display="None" ErrorMessage="need to fill it with words"> </asp:RequiredFieldValidator>
<asp:Button ID="bClick" runat="server" Text="Kerlick" />
</div>
</asp:Content>
我的母版页(不包括标题位)如下所示:
<body>
<form runat="server" id="Form1">
<div>
<asp:ContentPlaceHolder ID="cphMain" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="end">
</div>
</form>
</body>
单击按钮时,页面会抛出“Microsoft JScript 运行时错误:对象不支持此属性或方法” em>”错误,在函数的 WebResource.axd 中 ValidationSummaryOnSubmit(validationGroup)(第 512 行)。
事实证明,如果我将 ID="end" 的 div 的 id 更改为“end”以外的其他内容,则可以解决问题。
现在,我已经解决了这个问题,但我感兴趣的是为什么这首先会中断?
验证摘要是否有可能呈现具有相同 ID 的 div 并且在某处感到困惑?
Quick info: I'm using latest release of .NET 2.0, and the following is a stripped down test page I wrote to reproduce the error.
Excluding header bits, (there is no included/inline css or javascript) My content page looks like this:
<asp:Content ID="Content1" ContentPlaceHolderID="cphMain" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:TextBox ID="txtStuff" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtStuff" Display="None" ErrorMessage="need to fill it with words"> </asp:RequiredFieldValidator>
<asp:Button ID="bClick" runat="server" Text="Kerlick" />
</div>
</asp:Content>
My Master page (excluding header bits) looks like this:
<body>
<form runat="server" id="Form1">
<div>
<asp:ContentPlaceHolder ID="cphMain" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="end">
</div>
</form>
</body>
On clicking the button, the page throws an "Microsoft JScript runtime error: Object doesn't support this property or method" error, in WebResource.axd in the function
ValidationSummaryOnSubmit(validationGroup) (line 512).
Turns out, if I change the id of the div with ID="end" to something other than "end" it fixes the problem.
Now, I've fixed this problem, but I'm interested as to why this would break in the first place?
Is it possible that the validation summary renders a div with the same ID and is getting confused somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种确定的方法。
加载 firebug,调用validationsummary 并浏览页面以查看添加了哪些新元素。
通常,重复的 ID 不会产生问题,而且您没有设置 runat 服务器,因此它不是服务器端控件。
很有意思
One way to find out for sure.
Load up firebug, call the validationsummary and explore the page to see what new elements were added.
Normally a duplicate ID will not create an issue, plus you don't have runat server set so it's not a server side control.
Very interesting