10

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 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I needed to add the following after ValidatorEnable() to hide any existing validator messages. validator.isvalid = true; ValidatorUpdateDisplay(validator);
A better solution will be using jQuery selector of those validators where they may have a common css state, such as, hidden
3

You can disable the validators server-side:

MyFieldValidator.Enabled = MyCheckBox.Checked

Page.Validate()
If Page.IsValid Then
   'stuff
end if

Comments

2

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.

1 Comment

protected void NoValidation_CheckedChanged(object sender, EventArgs e) { SubmitButton.CausesValidation = !NoValidation.Checked; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.