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 style="font-size:12px;"></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 style="width:100px" align="right">用户名</td>
<td style="width:100px">
<asp:TextBox ID="TextBox5" runat="server"/>
</td>
</tr>
<tr>
<td style="width:100px" align="right">密码</td>
<td style="width :100px">
<asp:TextBox ID="TextBox6" runat="server"/>
</td>
</tr>
<tr>
<td style="width:100px">
</td>
<td style="width:100px">
<asp:Button ID="Button4" runat="server" Text="提交"/>
</td>
</tr>
<tr>
<td style="width:100px"/>
<td style="width:150px">
<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验证控件详解
现在ASP.NET,你不但可以轻松的实现对用户输入的验证,而且,还可以选择验证在服务器端进行还是在客户端进行,再也不必考虑那么多了,程序员们可以将重要精力放在主程序的设计上了. ASP.NET公有六种 ...
- 为人们服务的asp.net 验证控件
ASP.NET是微软推出的WEB开发工具,他有很强大的功能,今天看视频讲到验证控件这一部分,真的感受到了微软全心全意为人民服务了.越来越佩服微软了,人家都设计出来了,咱们一定要会用才可以啊,不然太…. ...
- ASP.Net 验证控件 RequiredFieldValidator
使用 ASP.NET 验证控件可在网页上检查用户输入.有用于各种不同类型验证的控件,例如范围检查或模式匹配验证控件.每个验证控件都引用网页上其他位置的输入控件(服务器控件).当处理用户输入时(例如,当 ...
- ASP.NET验证控件应用实例与详解。
ASP.NET公有六种验证控件,分别如下: 控件名 功能描叙 1RequiredFieldValidator(必须字段验证) 用于检查是否有输入值 2CompareValidator(比 ...
- ASP.NET_验证控件(class0620)
为什么使用验证控件 当需要让用户输入数据时,用户有可能输入不符合我们程序逻辑要求的信息,所以我们要对输入进行验证. 客户端验证(用户体验,减少服务器端压力) 服务器端验证(防止恶意攻击,客户端js很容 ...
- Asp.Net验证控件浅析
ASP.NET公有六种验证控件,分别如下: 控件名 功能描叙 RequiredFieldValidator(必须字段验证) 用于检查是否有输入值 CompareValidato ...
- ASP.NET验证控件一
为了更好地创建交互式Web应用程序.加强应用程序安全性,程序开发人员应该对用户输入的内容进行验证. ASP.NET提供了一系列输入验证控件,使用这些控件用户可以很方便地实现输入验证. ASP.NET还 ...
- ASP.Net 验证控件 RegularExpressionValidator
定义和用法 RegularExpressionValidator 控件用于验证输入值是否匹配指定的模式. 注释:除非浏览器不支持客户端验证或 EnableClientScript 属性被设置为 fal ...
- ASP.Net 验证控件 RangeValidator
RangeValidator 定义和用法 RangeValidator 控件用于检测用户输入的值是否介于两个值之间.可以对不同类型的值进行比较,比如数字.日期以及字符. 注释:如果输入控件为空,验证不 ...
随机推荐
- Ubuntu 12.04.2搭建nfs服务器
1.安装nfs 服务器(192.168.0.1) apt-get install nfs-kernel-server 2.修改nfs配置文件: vim /etc/exports 在exports文件中 ...
- git分支管理和stash
1 创建分支$ git branch 分支名 2切换到分支$ git checkout 分支名 3查看提交git log --oneline --decorate --graph --all 4 轻量 ...
- 采访ServiceStack的项目领导Demis Bellot——第2部分(转)
ServiceStack是一个开源的.支持.NET与Mono平台的REST Web Services框架.InfoQ有幸与Demis Bellot深入地讨论了这个项目.在这篇两部分报道的第2部分中,我 ...
- [ActionScript 3.0] AS3 绘制正八面体(线条)
分析: 将八面体置于3D坐标系中,其中心的坐标位于原点(0,0,0),让八面体的六个顶点恰好位于3D坐标系的x轴.y轴和z轴上,则从八面体的中心到这六个顶点的距离是相等的.我们可以假设这个距离为r,则 ...
- VisualVM连接远程Java进程
jstatd是一个RMI(Remove Method Invocation)的server应用,用于监控jvm的创建和结束,并且提供接口让监控工具(如VisualVM)可以远程连接到本机的jvms . ...
- codeforce--Vasya and Petya's Game
网址:http://codeforces.com/contest/576/problem/A A. Vasya and Petya's Game time limit per test 1 secon ...
- Spring-MongoDB简单操作
1.简单的配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http: ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...
- CODESOFT 2015中的二维码该怎样生成
由于二维条码具有储存量大.保密性高.追踪性高.抗损性强.备援性大.成本便宜等特性,其应用 渐趋广泛,因此二维码的制作对于CODESOFT条码设计软件的用户来讲可谓司空见惯.我们最常见的二维码要数QR码 ...
- JavaScript == VS ===
引用自 http://fxk2006.iteye.com/blog/768260 == equality 等同,两边值类型不同的时候,要先进行类型转换,再比较. === identity 恒等, ...