<html>
<head>
<title>CustomValidator Sample</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void serverValidate ( object src, ServerValidateEventArgs arg ) {
arg.IsValid = int.Parse ( arg.Value ) % 2 == 0;
}
void chkIsValid ( object src, EventArgs e ) {
if ( Page.IsValid ) message.InnerText = "Page has passed validation.";
}
</script>
<script language="javascript">
<!--
function clientValidate ( src, arg ) {
arg.IsValid = arg.Value % 2 == 0;
if ( !arg.IsValid ) message.innerText = "Enter an even number:";
}
// -->
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>CustomValidator Sample</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<center>
<form runat="server">
<span id="message" runat="server">Enter an even number:</span>
<p><asp:textbox id="myTextBox" size=6 runat="server" />
<br>
<asp:requiredfieldvalidator runat="server"
controltovalidate="myTextBox"
errormessage="Entry required." display="none" />
<asp:customvalidator runat="server"
controltovalidate="myTextBox"
clientvalidationfunction="clientValidate"
onServerValidate="serverValidate"
errormessage="Not an even number. Try again." display="none" />
<p>
<asp:button runat="server" text="Validate" onClick="chkIsValid" />
<asp:validationsummary runat="server"
displaymode="singleparagraph" showsummary=false showmessagebox />
</form>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>