Determine if page is valid in JavaScript - ASP.NET Determine if page is valid in JavaScript - ASP.NET asp.net asp.net

Determine if page is valid in JavaScript - ASP.NET


If I have a page that is using a bunch of ASP.NET validation controls I will use code similar to the following to validate the page. Make the call on an input submit. Hopefully this code sample will get you started!

    <input type="submit" value="Submit" onclick"ValidatePage();" />    <script type="text/javascript">    function ValidatePage() {        if (typeof (Page_ClientValidate) == 'function') {            Page_ClientValidate();        }        if (Page_IsValid) {            // do something            alert('Page is valid!');                        }        else {            // do something else            alert('Page is not valid!');        }    }</script>


You are checking for Page.IsValid where you should be checking for Page_IsValid (it's a variable exposed by the .NET validators) :)


The ASP.NET validation controls expose a client side API you can use with javascript: http://msdn.microsoft.com/en-us/library/aa479045.aspx

You should be able to check the Page_IsValid object to see if any of the validation controls are invalid.