Page 80 - DCAP312_WEB_TECHNOLOGIES_II
P. 80
Web Technologies-II
Notes
Figure 4.5: Validating whether an e-mail address is entered in a text box
1. The Custom Validator Control
We are not limited to the validation controls that have been shown thus far in this; we also
have the Custom Validator server control. The Custom Validator server control enables us to
develop our own custom server-side or client-side validations. At times, we may want to compare
the user’s input to a value in a database, or to determine whether his input conforms to some
arithmetic validation that we are looking for (for instance, if the number is even or odd). We
can do all this and more by using this type of validation control.
Client-Side Validation
One of the cool things about using the validation controls, in general, is that they allow for
client-side validation of certain HTML server controls. As anyone said, we can create our own
JavaScript functions that provide us with a higher level of validation capabilities.
Creating our own Client-Side Validation Functions
<%@ Page Language= “C#” %>
<script runat= “server”>
void Button1_Click(Object sender, EventArgs e) {
Label1.Text = “VALID NUMBER!”;
}
</script>
<html>
<head>
<script language= “JavaScript”>
function validateNumber(oSrc, args) {
args.IsValid = (args.Value % 5 == 0);
}
</script>
</head>
<body>
<form runat= “server”>
74 LOVELY PROFESSIONAL UNIVERSITY