Search code examples
asp.netvalidationsummary

Problem with ValidationSummary


I have a little contact-page on my asp.net page. I have ~5 validators that can go wrong there and I have a ValidationSummary.

The problem ist, when I hit the "SubmitButton" the div wit all controls should disappear and the div with the ValidationSummary should appear.

But I have no idea how to realiza that, because on a normal button / linkbutton I will not have a postback visible / invisible the DIV's. With a postback, I will not have the information for the ValidationSummary.

Hope I could explain it correctly, so you understand me :)


Solution

  • The validation summary shows/hides itself, is that something you want to control? At any rate, you are right, you have to do this in client-side JavaScript.

    One way is to manually call the validation method Page_ClientValidate, and don't rely on the default validation functionality.

    Another way is to replace the default client functionality by doing:

    var fn = Page_ClientValidate;
    Page_ClientValidate = function(..) {
       var result = fn(..);
    
       if (!!result)
          //Valid,
       else
          //Invalid, swap divs
    
       return result;
    }
    

    Take a look at the validation methods available to you on the client, that you can use this technique to override the default implementations: http://msdn.microsoft.com/en-us/library/aa338815(v=vs.71).aspx

    HTH.