Page 81 - DCAP312_WEB_TECHNOLOGIES_II
P. 81
Unit 4: Advanced Server Controls
<p> Notes
Number:
<asp:TextBox id= “TextBox1”
runat= “server”></asp:TextBox>
<asp:CustomValidator id= “CustomValidator1”
runat= “server” ControlToValidate= “TextBox1”
ErrorMessage= “Number must be divisible by 5”
ClientValidationFunction= “validateNumber”>
</asp:CustomValidator>
</p>
<p>
<asp:Button id= “Button1” onclick= “Button1_Click”
runat= “server” Text= “Button”></asp:Button>
</p>
<p>
<asp:Label id= “Label1” runat= “server”></asp:Label>
</p>
</form>
</body>
</html>
The important part of the Custom Validator server control here is the Client Validation Function
property. The value of this property must be the client-side JavaScript function that is in the
page in this case, the validate Number function. By simply using this with the Client Validation
Function property, we have tied the validation process to the custom client-side function that
we created, as illustrated in Figure 4.6.
Figure 4.6: Performing a custom client-side validation using the custom
validate server control
LOVELY PROFESSIONAL UNIVERSITY 75