views:

547

answers:

2

I'm looking to make validation for a page in which one or more fields have a value in them. I have an advanced search form in asp.net and I'm trying to pop up an error and not post back if all the fields are empty. I've looked into required fields validators but I'm not sure how to make them work together in a AND type fashion instead of the OR fashion that a validation group of required field validators would imply. I hope this makes sense. Thanks for the help.

+1  A: 

You could just write the javascript validation function yourself to handle this case and attach it to your search button.

Kevin Pang
+1  A: 

i had to do something similar years ago and i was using 1.1 then. what we ended up doing was creating required field validators but disabling them. then onload we would loop through the validator dictionary, enable them and check if they passed. if any of them passed we broke off the loop and we continued execution, otherwise, if all of them failed then we displayed a warning. Unfortunately, this would require a postback.

If you want to accomplish this on the client-side then you could write a simple javascript function to take care of it before postback. for every control, place an onBlur event. javascript will check if there is a value in the field and maintain a flag. then before submission you would check the flag and either allow submission or show warning.

Victor
Thanks alot, that was really bugging me. That will help me on alot of projects I think.
Cptcecil