views:

291

answers:

5

During the early stages of a dev cycle, it's a bit annoying to have all the validation controls enforcing their rules if we just want to move quickly from form to form.

What is the simplest way to disable all the validator controls on a page?

A: 

If you're allowed to input garbage data, might it be easier to put in a quick hack to let you just skip forward to the page you wanted to be on in the first place, instead of fiddling with validation?

Dean J
Maybe so. I was hoping there's just an easy way to "fiddle" with the validation and turn it off.
Larsenal
+1  A: 

Set up a javascript to get all the validator controls in your page and set their value to false in a for loop, something like this would work

function DisablePageValidators()
{   
 if ((typeof(Page_Validators) != "undefined") && (Page_Validators != null)) 
  {
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        ValidatorEnable(Page_Validators[i], false);
    }
  }
}
TStamper
You've done something seriously wrong if you don't validate server side too!
RichardOD
validate server side too? this person is trying to disable validation, so this method I posted would disable all the validation within the page
TStamper
Looking for a way to shut it all off--server side and client side.
Larsenal
Yes- so you are saying you don't check if the page is valid on the server side? You don't use this- http://msdn.microsoft.com/en-us/library/system.web.ui.page.isvalid.aspx
RichardOD
@RichardOD-Im not understanding what you're disagreeing with, you just posted the same answer I have to my understanding
TStamper
Server side validation can (and should) still take place even when Javascript is disabled. This doesn't prevent server-side validation and hence doesn't properly address the problem and really shouldn't be the accepted answer.
Dan Diplo
A: 

Remove them from the page.

rick schott
A: 

Try this :

Page_ValidationActive = false;

Neitcouq
A: 

Your best bet is to recursively loop through all controls on the page, looking for all controls that inherit from the BaseValidator class, and then set their Enabled property to False. You could write this as a simple library method.

Dan Diplo