Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 227927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:38:22+00:00 2026-05-11T19:38:22+00:00

A ValidationSummary will show a list of errors on postback. As each field is

  • 0

A ValidationSummary will show a list of errors on postback. As each field is fixed, it’s validator is fired, and any validation text will disappear. I want to automatically update the ValidationSummary as well.

The following works fine:

<asp:TextBox ID="ForenameTextBox" onblur="ValidationSummaryOnSubmit()" runat="server" />

but this isn’t ideal, as it means changing and maintaining this on all fields. (ValidationSummaryOnSubmit is a Microsoft function.) So I tried to do it dynamically:

addEvent(window, "load", UpdateValidationSummary);

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
    } else {
        if (obj.attachEvent) {
            var r = obj.attachEvent("on" + evType, fn);
            return r;
        }
    }
}

function removeEvent(obj, evType, fn) {
    if (obj.removeEventListener) {
        obj.removeEventListener(evType, fn, true);
        return true;
    } else if (obj.detachEvent) {
        var r = obj.detachEvent("on" + evType, fn);
        return r;
    }
}

function UpdateValidationSummary() {
    if (typeof (Page_Validators) == "undefined") {
        return;
    }
    var i, val, ctrl;
    for (i = 0; i < Page_Validators.length; i++) {
        val = Page_Validators[i];
        if (val.controltovalidate != null && val.controltovalidate != "") {
            ctrl = document.getElementById(val.controltovalidate);
            if (ctrl != null && typeof (ValidationSummaryOnSubmit) == "function") {
                //add call to ValidationSummary on blur
                addEvent(ctrl, "blur", ValidationSummaryOnSubmit);
            }
        }
    }
}

This doesn’t work though – the whole ValidationSummary disappears when one field is fixed, and the ValidationSummaryOnSubmit function seems to get called twice. If I use a simple assignment instead of the addEvent function it works, but I want to cater for fields that might already have something going on in the onBlur event.

Basically I think I just need to add a call to the ValidationSummaryOnSubmit function to the “list” of onBlur handlers for each control. Why doesn’t the code above seem to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:38:22+00:00Added an answer on May 11, 2026 at 7:38 pm

    Here’s a server-side approach to get the onblur attribute on all TextBoxes (which should also work with Validation Groups):

    • Create a class derived from TextBox, e.g., TextBoxEx
    • Add the attribute in this derived class e.g., this.Attributes.Add("onblur", string.Format("ValidationSummaryOnSubmit('{0}')", this.ValidationGroup);
    • Use tag mapping so that all of your existing <asp:TextBox> tags will still work:
      <system.web>
      <pages>
      <tagMapping>
      <add tagType="System.Web.UI.WebControls.TextBox"
      mappedTagType="MyControls.TextBoxEx"/>
      </tagMapping>
      </pages>
      </system.web>

    Another way would be to use ControlAdapters to add the attribute.

    Relevant links:
    Understanding ASP.NET Validation
    MSDN – tagMapping Element for pages

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 180k
  • Answers 181k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably have Items.Sorted=True. May 12, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer You can create a new JFrame from an Applet. But… May 12, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer You can check whether or not a given ordinal position… May 12, 2026 at 4:09 pm

Related Questions

I am working on rendering a dynamic form in an ASP.NET MVC view that
i have the requirement to show a nicely formatted error-message on top of the
I have a top-level page called ReceiveItem . Within that page, I have a
If you use a CustomValidator control and a ValidationSummary control within an aspx page

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.