Question

I'm getting an error on this line of javascript in IE8. It doesn't happen when the ValidationSummary is commented out. I believe this is the code that is generated by the control.

The ValidationSummary is on a UserControl that is used in a content page in asp.net.

When I use the IE developer tools it highlights this code

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" />
Was it helpful?

Solution

Turns out this is a known bug in the ajax control toolkit. They claim it's been fixed in the latest release, but I don't think it has. The fix is to create a server control that inherits from the validation summary and inserts the one missing semi-colon between the two javascript statements.

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

OTHER TIPS

The accepted answer, while it may work, may not be the best solution as it relies on script block registration order matching output order, which is not a good thing to rely on. From the MSDN page for 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.

Here is a possibly-better fix:

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

This bug is part of Validation controls in ASP.NET and not AJAX Toolkit. You can turn off client-side validation from all validation controls on your page with EnableClientScript="false" and the errors will be gone.

I had the same problem on Windows 7. The reason of this problem was with not current updates of Windows (Probably .NET was outdated). (I had turned off automatically updates). After install updates, the problem was solved

Had the same Problem but for a completly different Reason, had this code:

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

I had to explicitly disable the ValidationSummaryControl serverside if showvalidator was false. The Javascriptvalidationcode tries to find the summarycontrol (getelementbyid) but in was not rendered in the Page. Enableclientsidescript="false" remedys this because no javascriptcode is looking for the missing control anymore. I suppose this behavour was adressed in .NET 4.5 for the ValidationSummaryControl, so the Problem only occurs in .NET 4.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top