Home » CodeDigest


Enable/Disable Validator controls in ASP.Net
Submitted By Satheesh Babu B
On 2/5/2009 8:08:20 AM
Tags: ASP.Net,CodeDigest,JavaScript  

Enable/Disable Validator controls in ASP.Net

Sometimes, we will have requirements to enable/disable validator control for specific business conditions.

Enabling Disabling Validator control from JavaScript
One way is to set the enabled flag of the validation control to false and make it disabled.


  document.getElementById('RequiredFieldValidator2').enabled = false;


Again, setting it to true will enable it.

The other way will be calling inbuilt validation script's ValidatorEnable() method.




Calling this method with true in second argument will enable the validation control. This method will have its definition in the inbuilt validation script that gets downloaded to the client browser via web resource handler called WebResource.axd.


Enabling/Disabling a Validator control that belongs to a Validation Group

The below script will disable a validator control that belongs a validation group called "grp".

if(document.getElementById('RequiredFieldValidator2').validationGroup == "grp")
        document.getElementById('RequiredFieldValidator2').enabled = false;


Enabling/Disabling validator control from serverside
We can enable or disable a validator control from server side by setting the validator control's EnableClientScript property to true/false.

To disable a validator control,
RequiredFieldValidator2.EnableClientScript = false;


Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..