ASP.NET控件之CompareValidator控件

作用:对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>

感谢您的宝贵时间···

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

女汉纸一枚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值