I found the following javascript code on a blog , it uses ValidationGroup to switch validation controls, but you can just as easily remove if (Page_Validators[i].validationGroup == validationGroupName) and toggle the entire set of validators.
After calling the "ValidatorEnable" method, you will need to add your own activation code.
function HasPageValidators() { var hasValidators = false; try { if (Page_Validators.length > 0) { hasValidators = true; } } catch (error) { } return hasValidators; } function ValidationGroupEnable(validationGroupName, isEnable) { if (HasPageValidators()) { for (i = 0; i < Page_Validators.length; i++) { if (Page_Validators[i].validationGroup == validationGroupName) { ValidatorEnable($('[id*=DueDateRequiredValidator]')[0], true); } } } }
Edit: Victor, based on your comment, I think you can get the same results by adding attributes to your controls. This would group them without using ValidationGroups, and you can access attributes from JavaScript.
In your code behind, you need to set the attributes for the Validation controls as follows:
SampleValidator1.Attributes.Add("myGroupName", "sample1"); SampleValidator2.Attributes.Add("myGroupName", "sample2");
Then, in the Javascript function, instead of this line, `if (Page_Validators [i] .validationGroup == validationGroupName) {', use this:
if (Page_Validators[i].getAttribute('myClass') == 'sample1') {
This should get what you want without groups, but sorry - you will need to set the attribute
Last edit: I made it harder than necessary. I have not tried, but if you want to get the CSS class of an object in JavaScript, this is .className , not .class . Try this before any of my previous suggestions.