asp CustomValidator: validate event function (C#)
<%@ Page Language="C#" %>
<script runat="server">
void valProductCode_ServerValidate(Object source, ServerValidateEventArgs args)
{
if (args.Value.Length == 4)
args.IsValid = true;
else
args.IsValid = false;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show Validate Empty Text</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblProductCode"
Text="Product Code:"
AssociatedControlID="txtProductCode"
Runat="server" />
<br />
<asp:TextBox
id="txtProductCode"
Runat="server" />
<asp:CustomValidator
id="valProductCode"
ControlToValidate="txtProductCode"
Text="(Invalid product code)"
ValidateEmptyText="true"
OnServerValidate="valProductCode_ServerValidate"
Runat="server" />
<br /><br />
<asp:Button
id="btnSubmit"
Text="Submit"
Runat="server" />
</div>
</form>
</body>
</html>
Related examples in the same category