作用:对Textbox或者其他输入框进行比较验证;
属性:ControlToValidate:要验证的控件;
ErrorMessage:错误提示信息;
ControlToCompare:与此相比的控件ID;
Type
类型 | 作用 |
Integer | 整数型 |
Date | 日期 |
Double | 双精度浮点型 |
String | 字符串型 |
Currency | 货币类型 |
Operator:操作类型
操作类型 | 作用 |
Equal | 相等 |
NotEqual | 不相等 |
GreaterThan | 数据类型验证 |
GreaterThanEqual | 大于 |
LessThan | 大于等于 |
LessThanEqual | 小于 |
DataTypeCheck | 小于等于 |
原型:
Demo:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="非空验证.aspx.cs" Inherits="验证控件1.非空验证" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.auto-style1 {
position: absolute;
top: 159px;
left: 360px;
z-index: 1;
}
.auto-style2 {
position: absolute;
top: 190px;
left: 360px;
z-index: 1;
bottom: 452px;
width: 81px;
}
.auto-style3 {
position: absolute;
top: 158px;
left: 436px;
z-index: 1;
}
.auto-style4 {
position: absolute;
top: 189px;
left: 435px;
z-index: 1;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="Label1" runat="server" CssClass="auto-style1" Text="密码:"></asp:Label>
<asp:Label ID="Label2" runat="server" CssClass="auto-style2" Text="确认密码:"></asp:Label>
<asp:TextBox ID="txtPwd" runat="server" CssClass="auto-style3"></asp:TextBox>
<asp:TextBox ID="txtPwdOk" runat="server" CssClass="auto-style4"></asp:TextBox>
<p>
</p>
<p>
</p>
<asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" style="z-index: 1; left: 390px; top: 299px; position: absolute; width: 63px; height: 21px" Text="注册" />
<asp:Button ID="btnSet" runat="server" OnClick="btnSet_Click" style="z-index: 1; left: 559px; top: 299px; position: absolute; width: 64px; height: 21px" Text="重置" />
<asp:Label ID="Label3" runat="server" style="z-index: 1; left: 361px; top: 232px; position: absolute" Text="注册日期:"></asp:Label>
<asp:TextBox ID="txtDate" runat="server" style="z-index: 1; left: 434px; top: 229px; position: absolute; height: 15px"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPwd" ControlToValidate="txtPwdOk" ErrorMessage="*确认密码有误!" ForeColor="Red" style="z-index: 1; left: 598px; top: 192px; position: absolute" Operator="DataTypeCheck"></asp:CompareValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtDate" ErrorMessage="*日期格式不正确" ForeColor="Red" Operator="DataTypeCheck" style="z-index: 1; left: 598px; top: 231px; position: absolute" Type="Date"></asp:CompareValidator>
</form>
</body>
</html>
感谢您的宝贵时间···