I have a credit card transaction area in my form that I hide and show based on user's selection in an radio button group. With my credit card piece are required validations and required expressions that is in a validation group. I was wondering if I could get some help with enabling and disabling this validation group in J Query. Thanks in advance for your guys' help!
-
@Win what are your thoughts – Paradigm Apr 01 '13 at 15:25
4 Answers
I usually have a class that indicates whether a field should be validated or not, so when a field that should be validated is hidden, just remove the class. Add it again when it is displayed.
A more elegant solution is to disable validation of hidden fields:
$('myform').submit(function() {
$('myform').find('validate:visible').forEach( ... );
});

- 4,177
- 4
- 28
- 41
You can use ASP.NET built-in JavaScript function to enable and disable validators
var validtorObject = document.getElementById('validtorObjectID');
ValidatorEnable(validtorObject, false);
And this SO answer gives you easy way to disable all controls inside a validation group using JQuery
Enable/disable asp.net validator controls within a specific "ValidationGroup" with jQuery?

- 17,750
- 17
- 113
- 128

- 6,272
- 3
- 39
- 50
-
Would this work the same as using the validation group name for the validation Id? – Paradigm Apr 01 '13 at 14:05
-
Validation groups are different, this is just to disable individual validators. – Guru Kara Apr 01 '13 at 14:09
-
to disable required validator you can try
ValidatorEnable(document.getElementById("<%=RequiredFieldValidatorID %>"), false);

- 13,513
- 3
- 35
- 52
-
Would this work the same as using the validation group name for the validation Id? – Paradigm Apr 01 '13 at 14:06
You can set the CausesValidation="False"
CausesValidation property determines whether validation must be performed on button click or not, if asp.net validation control are used. It can be either true or false. By default it is true.
It is mostly used for Cancel/Reset button, where we don't want to perform any kind of validations.
protected void radioButton_CheckedChanged(object sender, EventArgs e)
{
creditCardTextbox.Attributes.Add("CausesValidation", "False");
}

- 3,066
- 3
- 27
- 38