0

我在 IE8 中的这行 javascript 上遇到错误。当 ValidationSummary 被注释掉时,它不会发生。我相信这是控件生成的代码。

ValidationSummary 位于 asp.net 的内容页面中使用的 UserControl 上。

当我使用 IE 开发人员工具时,它会突出显示此代码

document.getElementById('ctl00_ctl00_body_pageBody_ucCC1_valSummary').dispose = function() {
    Array.remove(Page_ValidationSummaries, document.getElementById('ctl00_ctl00_body_pageBody_ucCC1_valSummary'));
}
(function() {var fn = function() {Sys.Extended.UI.ModalPopupBehavior.invokeViaServer('ctl00_ctl00_body_pageBody_mdlPopupExtender', true); Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);})()




<asp:ValidationSummary 
runat="server" 
ID="valSummary" 
ShowSummary="true" 
DisplayMode="BulletList"
CssClass="summaryValidation" 
HeaderText="Errors:" 
ForeColor="White" 
ValidationGroup="VldGrpHospital" />
4

5 回答 5

1

原来这是 ajax 控制工具包中的一个已知错误。他们声称它已在最新版本中修复,但我认为没有。解决方法是创建一个从验证摘要继承的服务器控件,并在两个 javascript 语句之间插入一个缺少的分号。

http://ajaxcontroltoolkit.codeplex.com/workitem/27024

[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
    }
}
于 2012-02-14T22:13:09.733 回答
1

接受的答案虽然可能有效,但可能不是最佳解决方案,因为它依赖于脚本块注册顺序匹配输出顺序,这不是一件值得依赖的好事情。从 MSDN 页面获取RegisterStartupScript

使用 RegisterStartupScript 注册的启动脚本块不保证按照注册的顺序输出。如果启动脚本块的顺序很重要,请使用 StringBuilder 对象将脚本块收集到单个字符串中,然后将它们全部注册为单个启动脚本。

这是一个可能更好的解决方法:

public class ValidationSummarySansBug : ValidationSummary
{
    // The bug is that the base class OnPreRender renders some javascript without a semicolon.
    // This solution registers an almost-identical script *with* a semicolon using the same type and key and relies on the
    // behavior of ClientScriptManager.RegisterStartupScript to ignore duplicate script registrations for the same type/key
    protected override void OnPreRender(EventArgs e)
    {
        if (Enabled)
        {
            ScriptManager.RegisterStartupScript(
                this,
                typeof(ValidationSummary), // this type must match the base type's specified type for the script we're fixing
                ClientID + "_DisposeScript", // this key must match the base type key for the script we're fixing
                @"
document.getElementById('{0}').dispose = function() {{
    Array.remove(Page_ValidationSummaries, document.getElementById('{0}'));
}};
            ".FormatInvariant(ClientID),
                true);
        }

        base.OnPreRender(e);
    }
}
于 2015-01-19T19:31:25.930 回答
0

此错误是 ASP.NET 中的验证控件的一部分,而不是 AJAX 工具包的一部分。您可以从页面上的所有验证控件中关闭客户端验证,EnableClientScript="false"并且错误将消失。

于 2012-04-03T04:50:33.410 回答
0

我在 Windows 7 上遇到了同样的问题。这个问题的原因是没有当前的 Windows 更新(可能 .NET 已经过时)。(我已经关闭了自动更新)。安装更新后问题解决了

于 2014-03-12T13:16:58.680 回答
0

有同样的问题,但出于完全不同的原因,有这个代码:

<% if(showvalidators){ %>
<tr>
    <td>
    <asp:ValidationSummary ID="SummaryValidator" runat="server" ForeColor="Red" EnableClientScript="true" DisplayMode="BulletList" ShowMessageBox="false" HeaderText="" />
    </td>
</tr>
<%}%>

如果 showvalidator 为假,我必须明确禁用 ValidationSummaryControl 服务器端。Javascriptvalidationcode 尝试查找摘要控件 (getelementbyid) 但未在页面中呈现。Enableclientsidescript="false" 解决了这个问题,因为不再有 javascriptcode 正在寻找丢失的控件。我想这种行为是在 .NET 4.5 中针对 ValidationSummaryControl 解决的,所以问题只发生在 .NET 4.0

于 2014-04-28T14:26:32.703 回答