Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking the Page.isValid property on the form

Status
Not open for further replies.

gregburningham

Programmer
Jul 12, 2000
40
0
0
GB
Hi

I am trying to conditionally display a label on screen if validation has failed on a form. For instance if a field has not been correctly entered a Summary Validator shows that field as invalid.

I would also like to display a label on the page if the field is invalid. I have tried forcing validation in the Button Save event with Page.Validate() - then tried to use the if page.isValid check - but to no avail....

Anyone got any ideas ?

Thanks
Greg B


 
Maybe the problem is that asp.net validation normally works client side. Your validation summary control gets displayed by client script, and the server code to show the label never gets executed because no post back occurs if the validation criteria are not met?



Mark [openup]
 
Hi - Yeah this is the problem - I'm not sure how to test the status of validation at client side rather than server-side - any ideas?


Thanks
Greg B


 
Well, the validation summrary control is kinda designed to be the label which you want to use. Unfortunately, there does not appear to be a way to make it only display a certain message, and not to list all the errors individually.

If this does not suit your needs, then you could write yourself the validation routines client side in javascript or vbscript?

Or you could use a small client script routine to check if the asp.net javascript has made the valiation summary control visible
Code:
  <script language=vbscript>
  sub button1_onClick()
  if ValidationSummary1.style.display <> "none" then
  'make your label (a HTML div) style display = "inline"
  'whereas at design time, set it to "none"
  end if
  end sub
  </script>

I cannot guarantee that this method always works, though, as it depends on whether your code or the asp.net javascript is exec'd first.

Or you could do the validation server side, which kinda sucks.

Or you could look for or build a custom control which inherits SummaryValidator, but which has the behaviour you desire.

Hope you get it working

Mark


Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top