Access ASP.NET Validators from JavaScript

I needed to access clientside validators from JavaScript in order to determine if the page was valid or not.

Turns out MSDN tells you how if you dig deep enough. 🙂

You have two options:

  1. Access a global flag that essentially loops through all validators
  2. Check each validator, one at a time

#1 is the easy way, just use the Page_IsValid flag to determine this.

#2 isn’t so bad if you know all of your validators. If you do, you can simply access the validator.isvalid flag.

Lastly, it is sometimes useful to be able to force validation from JavaScript on a page before performing an action (such as clicking a submit button). In this case, you can simply call the Page_ClientValidate() function and that’s all it takes!


Jaxidian Update is proudly powered by WordPress and themed by Mukkamu