Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net disable/enable validator using Javascript

I have a complex form requiring me to switch specific validators on or off depending on selections made by the user.

ValidatorEnable seems to do the job, but it seems that when I call this method it actually fires the validation process as well, without the user actually hitting the submit button.

Is that how it works?

like image 203
Jacques Avatar asked Apr 21 '12 07:04

Jacques


2 Answers

I eventually found the best way to do this was to use the following code:

var validatorObject = document.getElementById('<%=ValidHasShippingLocationZip.ClientID%>');
validatorObject.enabled = false;
validatorObject.isvalid = true;
ValidatorUpdateDisplay(validatorObject);
like image 185
Jacques Avatar answered Oct 12 '22 21:10

Jacques


I wrote some code seems can meet your requests. Iterate validators and enable these you needs.

   ValidatorEnable(validatorObj, true);

then clear the screen,erase the error info.

The full code snippet can be found here http://codelife.cybtamin.com/enable-and-disable-asp-net-validator-by-javascript/

like image 38
ValidfroM Avatar answered Oct 12 '22 19:10

ValidfroM