13

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?

0

2 Answers 2

22

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);
Sign up to request clarification or add additional context in comments.

4 Comments

it worked, I didn't use the isvalid property, I worked just with the enable or disable
Why I'm still able to submit my asp.net form while the above function works with my validators and display / hide the validator? I don't use isValid in my code behind!
@DKR make sure you find correct validatorObject, maybe you should use console.log(validatorObject) to see if the element was find correctly.
It worked, but has 1 problem, Page.Isvalid still returns false (I mean on code-behind side)
1

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/

2 Comments

Don't just post links, links die.
ValidatorEnable(valObj, enable) is now part of the .NET boilerplate code so this example can be used without additional code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.