Web Studyaspnet.blogspot.com Babyneed.blogspot.com

ASP.Net Web Developer Guide

Power By: eXTReMe Tracker Powered by Blogger  
 
 
 
 

 

 
Important Links
 
   
     
 
Sitemap
 
   
   
 
Reference
 
   

Sunday, March 26, 2006

CustomValidator with Explicit Client-Side Validation Function (Chapter 3)

In the CustomValidator, we may specify a twin client-side validation function. To employ the client-side validation, we will have to specify the name of the client-side validation function in the ClientValidationFunction property of the CustomValidator control.The client-side function needs to be coded in JavaScript, and it should also return true or false.Obviously, the client-side validation should perform the same checks that are done by the server-side validation function. We will revise our previous example to include a client-side validation function. We have already developed the server-side validation function for the department number textbox. Now we will implement the client-side validation. The run-time display of the application is shown in Figure 3.58.
Figure 3.58 Using CustomValidator with Explicit Client-Side Validation

The part of the code that is pertinent to our example is shown in Figure 3.59. In this code, you will notice that we have specified the name of the JavaScript validation function in the ClientValidationFunction property of the control to be validated.
Figure 3.59 Partial Listing of Validator6.aspx
<asp:CustomValidator id="cusvDeptNum" runat="server"
display="dynamic" controlToValidate="txtDeptNum"
onServerValidate="validateDeptNum"
ClientValidationFunction="checkModTen"
errorMessage="Dept. Number must be a multiple of 10" >
</asp:CustomValidator></br>
<script language="javascript" >
function checkModTen(source, s)
{ var y=parseInt(s.Value);
if ((y % 10) == 0 && !(isNaN(y)))
s.IsValid=true;
else
s.IsValid=false;
}
</script>

0 Comments:

Post a Comment

<< Home