Disable some ASP.Net validation controls when a ch

2020-05-27 04:04发布

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?

3条回答
Ridiculous、
2楼-- · 2020-05-27 04:16

You can disable the validators server-side:

MyFieldValidator.Enabled = MyCheckBox.Checked

Page.Validate()
If Page.IsValid Then
   'stuff
end if
查看更多
Deceive 欺骗
3楼-- · 2020-05-27 04:25

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.

查看更多
狗以群分
4楼-- · 2020-05-27 04:38

If you're disabling server side then you can do

button1.CausesValidation = False

in your CheckChangedEvent this is more helpful if you have a lot of validators and need to disable them all.

查看更多
登录 后发表回答