Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/disable asp.net validator controls within a specific "ValidationGroup" with jQuery?

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?

like image 368
jessegavin Avatar asked Jan 28 '10 21:01

jessegavin


3 Answers

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);

   }
});
like image 187
womp Avatar answered Oct 21 '22 09:10

womp


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>
like image 22
keyboardP Avatar answered Oct 21 '22 09:10

keyboardP


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

like image 22
Imran Jawaid Avatar answered Oct 21 '22 09:10

Imran Jawaid