40

I want to check page validation on client side, like Page.Validate() but it's a server side method. Is there any client side function which can work like Page.Validate() with JavaScript?

2 Answers 2

76

Page_ClientValidate() will work. It returns true if the page was valid and it works fine.

If you are using ASP.NET 2.0, pass the validation group name as a parameter.
E.g.

if(Page_ClientValidate("SomeValidationGroup"))
     alert('its valid');

Otherwise if there is no validation group Page_ClientValidate("") will handle it.
E.g.

if(Page_ClientValidate(""))
     alert('its valid');
Sign up to request clarification or add additional context in comments.

3 Comments

This is the quick answer. Tim's answer gives more detail if needed, just no examples.
Note though that the Page_ClientValidate() does not exist if there are no validators on the page. So make sure to always check if it's there.
In my case, using Page_ClientValidate() derailed the functionality set up by the back end. Instead of performing the validation it just always returned true and no other validation actions or submission steps occurred. To the user the form didn't change.
25

There is a mini-clientside-validation API:

http://msdn.microsoft.com/en-us/library/aa479045.aspx#aspplusvalid_clientside

alt text

and here are some functions to trigger validation on validators:

alt text

Comments

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.