码迷,mamicode.com
首页 > Web开发 > 详细

ASP.Net 验证控件 CompareValidator

时间:2015-02-08 12:42:43      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

CompareValidator

作用就是比较两个输入框所输入的值是否一致,常用来作为验证输入密码和确认密码的业务。

 

属性 描述
Operator 比较操作符,可选值DataTypeCheck、Equal、GreaterThan、GreaterThanEqul、LessThan、LessThanEqual、NotEqual
ValueToCompare 所比较的运算符右边的值
ControlToCompare 设定与另外一个控件进行比较
Type 数据类型可选StringIntegerDoubleDateCurrency

 

 

 

 
 
 
 
 
 
•ControlToValidate  (符号左边的)
•ControlToCompare  待比较的控件(符号右边的)
•Operator 比较操作
•Type属性

 

 技术分享

技术分享
 1 <form id="form1" runat="server">
 2     <div>
 3     <table border="1">
 4         <tr>
 5             <td class="style1">Password</td>
 6             <td class="style2">
 7                 <asp:TextBox ID="txtPwd" runat="server" TextMode="Password"></asp:TextBox>
 8             </td>
 9         </tr>
10         <tr>
11             <td class="style1">Confirm Password</td>
12             <td class="style2"> 
13                 <asp:TextBox ID="txtConfirmPwd" runat="server" TextMode="Password"></asp:TextBox>
14                 <asp:CompareValidator ID="CompareValidator1" runat="server" 
15                     ControlToCompare="txtPwd" ControlToValidate="txtConfirmPwd" 
16                     ErrorMessage="*Password not match" ForeColor="Red"></asp:CompareValidator>
17             </td>
18         </tr>
19     </table>
20         <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
21     </div>
22     </form>
View Code

 

与一个定值进行比较

•ValueToCompare
•Operator 比较操作
•Type属性
 
技术分享

 

技术分享
 1 <form id="form1" runat="server">
 2     <div>
 3     <table border="1">
 4         <tr>
 5             <td class="style3">Input value </td>
 6             <td class="style4">
 7                 <asp:TextBox ID="txtValue" runat="server" TextMode="Number"></asp:TextBox>
 8                 <asp:CompareValidator ID="CompareValidator1" runat="server" 
 9                     ControlToValidate="txtValue" ErrorMessage="* Number is not greater than 100" 
10                     ForeColor="Red" Operator="GreaterThan" Type="Integer" ValueToCompare="100"></asp:CompareValidator>
11             </td>
12         </tr>
13         <tr>
14             <td class="style1">
15                 <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
16             </td>
17             <td class="style2"> &nbsp;</td>
18         </tr>
19     </table>
20     </div>
21     </form>
View Code

 

 

 

ASP.Net 验证控件 CompareValidator

标签:

原文地址:http://www.cnblogs.com/dreamtaker/p/4279783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!