• vs 基本验证控件使用


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASP.Default" %>
     
    <!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>
             <script>
                 function validateLength(oSrc, args) {
                     args.IsValid = (args.Value.length >= 8);
                     //如果args.IsValid=false,那么服务器将不会执行button的任何操作.
                 }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <h5>登录</h5>
        RequiredFieldValidator:非空验证
        <hr />
            <br />
        重要的属性:<br />
        1,ControlToValidate:要验证的控件<br />
        2,ErrorMessage:错误提示信息<br />
    &nbsp;<hr />
        用户账号:<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ControlToValidate="txtUsername" ErrorMessage="请输入用户名"></asp:RequiredFieldValidator>
            <br />
                    密&nbsp;&nbsp;&nbsp;&nbsp;码:<asp:TextBox ID="txtUserpass" 
                runat="server" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                ControlToValidate="txtUserpass" ErrorMessage="请输入密码"></asp:RequiredFieldValidator>
            <br />
    &nbsp;&nbsp;
            <asp:Button ID="btnSubmit" runat="server" Text="登录" />
            <br />
        </div>
            <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=&quot;Equal&quot; Type=&quot;String&quot;<br />
            1,用户注册时,<br />
            密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 码:<asp:TextBox ID="txtUserpass2" 
                runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                ControlToValidate="txtUserpass2" ErrorMessage="请输入密码"></asp:RequiredFieldValidator>
            <br />
            重复密码:<asp:TextBox ID="txtUserpass3" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                ControlToValidate="txtUserpass3" Display="Dynamic" ErrorMessage="请输入重复密码"></asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidator1" runat="server" 
                ControlToCompare="txtUserpass2" ControlToValidate="txtUserpass3" 
                ErrorMessage="重复密码有误" Operator="Equal"
                 
                ></asp:CompareValidator>
            <br />
            <br />
            <br />
            Operator=&quot;GeaterThan&quot; Type=&quot;Currency&quot;<br />
            2,请输入您应付金额:<asp:TextBox ID="txtMoney" runat="server"></asp:TextBox>
            <asp:CompareValidator ID="CompareValidator2" runat="server" 
                ControlToValidate="txtMoney" ErrorMessage="您输入的金额有误" Operator="GreaterThan" 
                Type="Currency" ValueToCompare="100"></asp:CompareValidator>
            <br />
            <input id="Reset1" type="reset" value="重置" />&nbsp;&nbsp;
            <asp:Button ID="Button1" runat="server" Text="提交" />
            <br />
        
        </div>
            <div>
    <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="Button2" runat="server" Text="Button" />
            </div>
        </form>
    </body>
    </html>
    
    再三须慎意,第一莫欺心
  • 相关阅读:
    利用正则表达式去掉html代码
    TYPE='application/xshockwaveflash'
    SQL存储过程事务和优化方法(包括查询方式语句结合)
    C#中Bitmap类实现对图像操作的一些方法
    回首往事,碩果累累,展望未來,信心滿懷。
    此方法用于确认用户输入的不是恶意信息
    js去除字符串中的空格
    SQLServer存储过程中的简单事务处理
    SQL 2000中行加入序号用法
    C#中将byte数组转换为8bit灰度图像
  • 原文地址:https://www.cnblogs.com/otsf/p/8521901.html
Copyright © 2020-2023  润新知