Monday, February 18, 2013

ASP.Net client side validation using Page_ClientValidate


ASP.Net client side validation using Page_ClientValidate
In typical web forms validators such as required field validators, regular expression validators, etc. are using with regular asp.net controls. With validation groups part of the controls in the web form can be validate. But with some of client events such as ‘OnClientClick’ those validations may not work as intended.  In such scenarios some mechanism has to use to check the validity of the validators to avoid unnecessary post backs. For achieve this java script Page_ClientValidate() function can be used.\\
 
Page_ClientValidate() function returns true or false based on the validity of the validators in the web form.


e.g :-
   if(retValue != null && Page_ClientValidate()){  //retValue is some variable
      return true;
   }
   else{
     return false;
   }
</ code>

Page_ClientValidate function can be used to validate controls which are belong to a validation group only.


e.g :-
   if(retValue != null && Page_ClientValidate('theGroup')){  //thGroup is a validation group
      return true;
   }
   else{
     return false;
   }


No comments:

Post a Comment