2012-02-13 201 views
0

我在IE8的这一行javascript中收到错误消息。当ValidationSummary被注释掉时不会发生。我相信这是由控件生成的代码。验证摘要javascript错误

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" /> 
+0

@GrailsGuy(可能还有其他人),我猜沿_TypeError线的东西:(中间值)(...)不是一个函数。或者至少这是我通过拥有一个ASP.NET'ValidationSummary'控件并尝试显示一个'ModalPopupExtender'控件(Ajax控件工具包)的经验。 – WynandB 2013-10-09 04:42:16

回答

1

原来这是在AJAX控件工具包一个已知的bug。他们声称它已在最新版本中得到修复,但我认为它没有。解决方法是创建一个从验证摘要继承的服务器控件,并在两个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); 
    } 
} 
0

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

+0

我不确定,除非我们正在讨论完全不同的错误。正如我在使用旧版本的Ajax Control Toolkit进行测试时不会得到[相同的] JavaScript错误一样。尽管在控件上设置了“EnableClientScript =”False“”。 – WynandB 2013-10-09 04:47:54

0

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

0

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

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

我必须明确禁用ValidationSummaryControl服务器端,如果showvalidator是假的。 Javascript验证码尝试查找summarycontrol(getelementbyid),但未在页面中呈现。 Enableclientsidescript =“false”可以解决此问题,因为没有javascriptcode正在查找丢失的控件。我想这个行为是在.NET 4.5中为ValidationSummaryControl提出的,所以这个问题只发生在.NET 4.0中。

1

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

Startup script blocks that are registered by using RegisterStartupScript are not guaranteed to be output in the same order in which they are registered. If the order of the startup script blocks is important, use a StringBuilder object to gather the script blocks in a single string, and then register them all as a single startup script.

这里可能是一个有更好的解决办法:

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); 
    } 
}