0

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!

Paradigm
  • 189
  • 1
  • 5
  • 21

4 Answers4

0

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( ... );
});
mzedeler
  • 4,177
  • 4
  • 28
  • 41
0

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?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
Guru Kara
  • 6,272
  • 3
  • 39
  • 50
0

to disable required validator you can try

 ValidatorEnable(document.getElementById("<%=RequiredFieldValidatorID %>"), false);
COLD TOLD
  • 13,513
  • 3
  • 35
  • 52
0

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");
}
Prakash Chennupati
  • 3,066
  • 3
  • 27
  • 38