1

Can anyone tell me what is the best way to disable validator control using JavaScript?

Which one is the best way to dsiable validation control(considering compatability as well)? Any help is greatly appreciated.

1]

var validatorObject = document.getElementById('<%=ValidatorControl.ClientID%>');
ValidatorEnable(validatorObject , true);

2]

var validatorObject = document.getElementById('<%=ValidatorControl.ClientID%>');
validatorObject.enabled = false;

Thanks.

1 Answer 1

1

When you call ValidatorEnable(val, enable) it calls a function that looks like this:
(to see it open the WebRescouce.axd script)

function ValidatorEnable(val, enable) {
    val.enabled = (enable != false);
    ValidatorValidate(val);
    ValidatorUpdateIsValid();
}  

By just enabling/disabling the validator(line 3), you can achieve what you want.
Also, calling ValidatorEnable which further calls ValidatorUpdateDisplay will immediately validate the associated control and show any validation messages.


According to me rather than using multiple js calling better would be using

var validatorObject = document.getElementById('<%=ValidatorControl.ClientID%>');
validatorObject.enabled = false;  

which simply serve's your purpose of enabling/disabling the validator...
Reference Help

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Bhavik, but I would like to know which one is the best way to disable validator control.

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.