views:

706

answers:

2

I'm using old fashioned ASP.NET validation (ugh) for a checkout process. I have a checkbox "I'll call with my credit card details". If checked I need to disable the required field validator and cc validator for the credit card number both on the client and on the postback.

How do it do it? Thanks!

+2  A: 

You can disable the validators server-side:

MyFieldValidator.Enabled = MyCheckBox.Checked

Page.Validate()
If Page.IsValid Then
   'stuff
end if
Eduardo Molteni
+4  A: 

You can disable the validators client-side (in javascript):

function disable(validatorId)
{
   var validator = document.getElementById(validatorId);
   ValidatorEnable(validator, false);
}

Where validatorId is the clientID of the validator to be disabled. See this page for a complete example.

M4N
Will check it out, and act accordingly - thank you.
Mike Kingscott
I needed to add the following after ValidatorEnable() to hide any existing validator messages.validator.isvalid = true; ValidatorUpdateDisplay(validator);
Daniel Ballinger