首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ValidationSummary javascript错误

ValidationSummary javascript错误
EN

Stack Overflow用户
提问于 2012-02-14 01:15:54
回答 5查看 4.1K关注 0票数 0

我在IE8中的这行javascript上得到了一个错误。当ValidationSummary被注释掉时,就不会发生这种情况。我相信这是由控件生成的代码。

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

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

代码语言:javascript
复制
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" />
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-02-15 06:13:10

事实证明,这是ajax控件工具包中的一个已知错误。他们声称在最新的版本中已经修复了这个问题,但我不认为是这样的。修复方法是创建一个从验证摘要继承的服务器控件,并在两个javascript语句之间插入一个缺少的分号。

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

代码语言:javascript
复制
[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
    }
}
票数 1
EN

Stack Overflow用户

发布于 2015-01-20 03:31:26

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

不保证使用RegisterStartupScript注册的

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

这里有一个可能更好的解决方案:

代码语言:javascript
复制
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);
    }
}
票数 1
EN

Stack Overflow用户

发布于 2012-04-03 12:50:33

此错误是ASP.NET中验证控件的一部分,而不是AJAX Toolkit。您可以使用EnableClientScript="false"从页面上的所有验证控件中关闭客户端验证,这样错误就会消失。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9264846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档