ASP.NET中 CompareValidator(比较验证)的使用

1.A,运行效果返回顶部

CompareValidator:比较验证


属性:
ControlToValidate:要验证的控件ID
ErrorMessage:错误提示信息
ControlToCompare:与此相比的控件ID
Operator:操作类型
     1,Equal:相等      2,NotEaula:不相等      3,DataTypeCheck:数据类型验证      4,GreaterThan:大于      5,GreaterThanEqual:大于等于      6,LessThan:小于      7,LessThanEqual:小于等于      
Type:类型
    Integer【整数型】;Date【日期】;Double【双精度浮点型】;String【字符串型】;Currency[货币类型]      
ValueToCompare:比较值

Operator="Equal" Type="String"
1,用户注册时,
密        码:       
重复密码:      重复密码有误 


Operator="GeaterThan" Type="Currency"
2,请输入您应付金额:      您输入的金额有误 
     
 
1.B,源代码返回顶部
/Demo4.aspx
复制代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Demo4.aspx.cs" Inherits="Demo4" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页title>
head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>CompareValidator:比较验证h2>
    <hr />
    属性:<br />
    ControlToValidate:要验证的控件ID<br />
    ErrorMessage:错误提示信息<br />
    ControlToCompare:与此相比的控件ID<br />
    Operator:操作类型<br />
    <pre>
     1,Equal:相等
    2,NotEaula:不相等
    3,DataTypeCheck:数据类型验证
    4,GreaterThan:大于
    5,GreaterThanEqual:大于等于
    6,LessThan:小于
    7,LessThanEqual:小于等于
    pre>
    Type:类型<br />
    <pre>
    Integer【整数型】;Date【日期】;Double【双精度浮点型】;String【字符串型】;Currency[货币类型]
    pre>
    ValueToCompare:比较值
    <hr />
    
        <br />
        Operator="Equal" Type="String"<br />
        1,用户注册时,<br />        码:<asp:TextBox ID="txtUserpass" 
            runat="server">asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="txtUserpass" ErrorMessage="请输入密码">asp:RequiredFieldValidator>
        <br />
        重复密码:<asp:TextBox ID="txtUserpass2" runat="server">asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtUserpass2" Display="Dynamic" ErrorMessage="请输入重复密码">asp:RequiredFieldValidator>
        <asp:CompareValidator ID="CompareValidator1" runat="server" 
            ControlToCompare="txtUserpass" ControlToValidate="txtUserpass2" 
            ErrorMessage="重复密码有误" Operator="Equal"
             
            >asp:CompareValidator>
        <br />
        <br />
        <br />
        Operator="GeaterThan" Type="Currency"<br />
        2,请输入您应付金额:<asp:TextBox ID="txtMoney" runat="server">asp:TextBox>
        <asp:CompareValidator ID="CompareValidator2" runat="server" 
            ControlToValidate="txtMoney" ErrorMessage="您输入的金额有误" Operator="GreaterThan" 
            Type="Currency" ValueToCompare="0">asp:CompareValidator>
        <br />
        <input id="Reset1" type="reset" value="重置" />  
        <asp:Button ID="Button1" runat="server" Text="提交" />
        <br />
    
    div>
    form>
body>
html>
复制代码
1.C,资源下载返回顶部

http://files.cnblogs.com/ylbtech/WebForm-BasicControl-Validator.rar

你可能感兴趣的:(ASP.Net)