Enable or disable asp.net validation controls from Java Script

I like Asp.net validation controls because they work on client side as well as on server side. Some time we need to disable validation controls from server side and then enable them on client side depending on some condition (for example if a particular checkbox or radio button is checked). The following code can be used in Java script to enable a validation control.

 ValidatorEnable(document.getElementById("<%=MyValidationControl.ClientID%>"), true); 

Same line of code will disable a validation control if we replace true with false. ValidatorEnable is a funtion provided by validation controls client side API. A useful boolean property of this API is isvalid and it is associated with each validation control. It is different from IsValid server side property. False is returned if given input is not validated by the validation control.

For more details on asp.net validation controls please see this nice article.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s