<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script>
function validateLength(oSrc, args) {
args.IsValid = (args.Value.length >= 8);
//如果args.IsValid=false,那么服务器将不会执行button的任何操作.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="csd" runat ="server" ClientValidationFunction ="validateLength"
ErrorMessage="长度必须是8位" ControlToValidate="TextBox1"></asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<div id="div"></div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</form>
</body>
</html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script>
function validateLength(oSrc, args) {
args.IsValid = (args.Value.length >= 8);
//如果args.IsValid=false,那么服务器将不会执行button的任何操作.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="csd" runat ="server" ClientValidationFunction ="validateLength"
ErrorMessage="长度必须是8位" ControlToValidate="TextBox1"></asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<div id="div"></div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</form>
</body>
</html>