4

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 :)

PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
  • ValidationSummary shows errors that occurred (no postback necessary if you have client side scripts for validation). If you are showing the ValidationSummary, then you have errors, how then if you hide the controls will they fix them? – Prescott Apr 14 '11 at 16:33
  • I think you should use custom validator, and if it fails, hide the Divs – Ali Apr 14 '11 at 16:39
  • Why are you making people round-trip to the server instead of letting them fix it right there? As a user, that would frustrate me. Also, some browser will not save the state of the form controls (back button) so then they'd have to retype things. – Nikki9696 Apr 14 '11 at 16:48

1 Answers1

3

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.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257