Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable some ASP.Net validation controls when a checkbox is checked

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?

like image 835
Kyle West Avatar asked Apr 21 '09 22:04

Kyle West


2 Answers

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.

like image 107
M4N Avatar answered Oct 13 '22 17:10

M4N


You can disable the validators server-side:

MyFieldValidator.Enabled = MyCheckBox.Checked

Page.Validate()
If Page.IsValid Then
   'stuff
end if
like image 33
Eduardo Molteni Avatar answered Oct 13 '22 15:10

Eduardo Molteni