9

I know how to enable/disable individual validator controls on the client side using

ValidatorEnable(validator, false);

But how do you enable/disable all the validators within a ValidationGroup?

jessegavin
  • 74,067
  • 28
  • 136
  • 164

3 Answers3

19

The validator properties aren't rendered as attributes unfortunately, so I don't know a good way to select them directly. You can try to iterate the Page_Validators array and filter out the ones you want to work with.

Try:

$.each(Page_Validators, function (index, validator){
   if (validator.validationGroup == "your group here"){

      ValidatorEnable(validator, false);

   }
});
womp
  • 115,835
  • 26
  • 236
  • 269
  • ??? i was shocked! First: this works, thanks for that. But my question is: Why can you use Page_Validators, and don't you have to use $("#Page_Validators") ? (which doesn't work :-)) – Michel Nov 15 '11 at 09:18
  • You should really have given the real answer to @Imram – Fandango68 Feb 05 '16 at 04:57
  • 1
    @Fernando68 He answered the question *2 years* later. – womp Feb 10 '16 at 01:12
2

Check this blogpost explaining how with javascript. The main part of the code from the blog:

<script type="text/javascript">
        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(Page_Validators[i], isEnable);
                    }
                }
            }
        }
    </script>
keyboardP
  • 68,824
  • 13
  • 156
  • 205
1

Alternatively you can simply have ValidationGroup attribute with each validator defined .

Then you wont need any Jquery or javascript stuff to close them.

Here is the link that worked for me.

http://www.w3schools.com/aspnet/showasp.asp?filename=demo_prop_webcontrol_imagebutton_validationgroup

Imran Jawaid
  • 471
  • 1
  • 10
  • 27
  • You are a legend! Yeah so simple. I tried trapping UpdatePanel from code-behind so as to turn off validators on another panel and place triggers from codebehind just so the update panel treats its validars separately! Arrggh you saved me hours – Fandango68 Feb 05 '16 at 04:56
  • Thank you, but the link now returns 404 – iokevins Apr 12 '21 at 01:59