星空网 > 软件开发 > ASP.net

ASP.NET验证控件二

RequiredFieldValidator 验证控件

  页面布局:

<div>    <h1>RequiredFieldValidator 验证控件</h1>      用户名:    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" Display="Dynamic"
ErrorMessage="用户名不能为空!"></asp:RequiredFieldValidator> <br/> <asp:Button ID="Button1" runat="server" Text="登录"></asp:Button> <hr/> <hr/><span ></div></span>

 

CompareValidator 验证控件

  页面布局:

<div>    <h1>CompareValidator 验证控件</h1>      价格:    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>         <asp:CompareValidator ID="CompareValidator" runat="server" ControlToValidate="TextBox2"       ErrorMessage="输入大于0的数值" Operator="GreaterThan" Type="Double" ValueToCompare="0">    </asp:CompareValidator>    <asp:Button ID="Button2" runat="server" Text="提交"/>    <hr/>    <hr/></div>

 

RangeValidator 控件

  页面布局:

<div>     <h1>RangeValidator 控件</h1>       价格:     <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>     <asp:RangeValidator ID="RangeValidator" runat="server" ControlToValidate="TextBox3"        ErrorMessage="请输入300~900之间的数" MaximumValue="900" MinimumValue="300" Type="Double" >     </asp:RangeValidator> </div> 

 

RegularExpressionValidator控件

  页面布局:

<div>    <h1>RegularExpressionValidator 控件</h1>      电话号码:    <asp:TextBox ID="TextBox4" runat="server"/>    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox4"       Display="Dynamic" ErrorMessage="输入合格电话号码如423-875416952" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{8}"/>    <asp:Button ID="Button3" runat="server" Text="提交"/></div>

 

CustomValidator控件

  页面布局:

<div>    <h1>CustomValidator控件</h1>    <table>      <tr>        <td align="right">用户名</td>        <td >          <asp:TextBox ID="TextBox5" runat="server"/>        </td>      </tr>      <tr>        <td align="right">密码</td>        <td >          <asp:TextBox ID="TextBox6" runat="server"/>        </td>      </tr>      <tr>        <td >        </td>        <td >        <asp:Button ID="Button4" runat="server" Text="提交"/>        </td>      </tr>      <tr>        <td />        <td >          <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="用户名或密码错误"            ValidateEmptyText="true" ControlToValidate="TextBox6" OnServerValidate="CustomValidator1_ServerValidate"            DisPlay="Dynamic">          </asp:CustomValidator>        </td>      </tr>    </table>  </div>

  后台代码:

 //自定义验证函数    private bool IsPassed(string userName, string password)    {      if (userName == "zhouzhou" && password == "123456")        return true;      else        return false;    }    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)    {      if (IsPassed(this.TextBox5.Text.ToString(), this.TextBox6.Text.ToString()))//调用自定义函数        args.IsValid = true;//通过验证      else        args.IsValid = false;//未通过验证    }

 

原文链接:

http://blog.csdn.net/spilledlight/article/details/48730647

 




原标题:ASP.NET验证控件二

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

雅玛森_东莞市雅玛森商务咨询有限公司:https://www.ikjzd.com/w/1395
特许金融分析师:https://www.ikjzd.com/w/1396
WorldRemit_在线跨国转账服务商:https://www.ikjzd.com/w/1397
iZettle:https://www.ikjzd.com/w/1398
eBay两步验证法:https://www.ikjzd.com/w/1399
Amazon Echo:https://www.ikjzd.com/w/140
珠海长隆横琴剧院在哪里?附禁带物品:https://www.vstour.cn/a/334173.html
珠海长隆横琴剧院坐公交怎么去:https://www.vstour.cn/a/334174.html
相关文章
我的浏览记录
最新相关资讯
跨境电商服务平台 | 深圳旅行社 | 东南亚物流