ASP.NET控件之RequiredFieldValidator控件
作用:对textbox或者其他输入框进行非空验证;
属性:ControlToValidate (选择要指向的控件)
ErrorMessage(错误,输入要显示的错误信息)
应用方法:
原型:
Demo
前端:
<span style="font-family:KaiTi_GB2312;font-size:18px;"><%@ 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;
}
.auto-style5 {
position: absolute;
top: 159px;
left: 601px;
z-index: 1;
}
.auto-style6 {
position: absolute;
top: 196px;
left: 605px;
z-index: 1;
height: 15px;
width: 109px;
}
</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="txtUserName" runat="server" CssClass="auto-style3"></asp:TextBox>
<asp:TextBox ID="txtPwd" runat="server" CssClass="auto-style4"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtUserName" CssClass="auto-style5" ErrorMessage="*请输入用户名" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPwd" CssClass="auto-style6" ErrorMessage="*请输入密码" ForeColor="Red"></asp:RequiredFieldValidator>
<p>
</p>
<p>
</p>
<asp:Button ID="btnLogin" runat="server" style="z-index: 1; left: 389px; top: 259px; position: absolute; width: 63px; bottom: 360px" Text="登录" />
<asp:Button ID="btnSet" runat="server" OnClick="btnSet_Click" style="z-index: 1; left: 559px; top: 262px; position: absolute; width: 64px; height: 21px" Text="重置" />
</form>
</body>
</html>
</span>
后台:
<span style="font-family:KaiTi_GB2312;font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace 验证控件1
{
public partial class 非空验证 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
//重置
protected void btnSet_Click(object sender, EventArgs e)
{
txtPwd.Text = "";
txtUserName .Text ="";
}
//登录
protected void btnLogin_Click(object sender, EventArgs e)
{ }
}
}</span>
小结
1、多多总结吧,万一哪天用到了呢···
感谢您的宝贵时间···
ASP.NET控件之RequiredFieldValidator控件的更多相关文章
- RequiredFieldValidator控件--必填验证控件
RequiredFieldValidator控件: ·RequiredFieldValidator控件也被称之为必填验证控件,顾名思义,也就是与RequiredFieldValidator控件关联的控 ...
- ASP.NET关于Login控件使用,LoginView 控件,CreateUserWizard 控件
原文:ASP.NET关于Login控件使用,LoginView 控件,CreateUserWizard 控件 Login控件它是属于Membership服务的一部分,必须配置Membership提供程 ...
- asp.net控件的Hyperlink控件
Asp.net控件: Hyperlink控件:Hyperlink控件又称为超链接控件,该控件在功能上跟Html的<a herf=””>控件相似,其显示的模式为超链接的形式. 注意: Hyp ...
- 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>
ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...
- 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>
分页 在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...
- RequiredFieldValidator 控件 CompareValidator 控件
RequiredFieldValidator 控件 验证关联控件非空 ControlToValidate 属性用来关联被验证控件 ErrorMEssage 触发控件后显示的错误信息 CompareVa ...
- 027. asp.net中数据绑定控件之 GridView控件
GridView控件支持下面的功能: 绑定至数据源控件, 如SqlDataSource 内置排序功能 内置更新和删除功能 内置分页功能 内置行选择功能 可以编程方式访问GridView对象模型以动态设 ...
- asp.net 弹出式日历控件 选择日期 Calendar控件
原文地址:asp.net 弹出式日历控件 选择日期 Calendar控件 作者:逸苡 html代码: <%@ Page Language="C#" CodeFile=&quo ...
- asp.net学习之 数据绑定控件--List数据绑定控件
原文:asp.net学习之 数据绑定控件--List数据绑定控件 List控件(如 CheckBoxList.DropDownList.ListBox 和 RadioButtonList 类)继承自L ...
随机推荐
- php设计模式课程---2、为什么会用到简单工厂设计模式
php设计模式课程---2.为什么会用到简单工厂设计模式 一.总结 一句话总结: 比如调用数据库的语句,如果调用的数据库名字改了,或者调用的数据库类型改了(比如从Mysql用到了Mysqli),那么要 ...
- idea中java异常
1. Compilation failed: internal java compiler error 解决方案:File-->Setting...-->Build,Execution,D ...
- 我对java的理解(二)——反射是小偷的万能钥匙
在我们生活中,车上或者路上有时候会遇到一种很讨厌的人——“小偷”,趁我们不注意或者疏忽的时候拿走属于我们的东西.更有甚者,趁我们不在家的时候,手持一把万能钥匙,打开我们的房门,悠闲的查看房间的布置,翻 ...
- IP通信中音频编解码技术与抗丢包技术概要
此文较长,建议收藏起来看. 一.一个典型的IP通信模型 二.Server2Server技术分类 Server2Server这块也是一个专门的领域,这里只简单分个类. 1.同一国家相同运营商之间: 同一 ...
- uoj problem 11 ydc的大树
题目大意: 给定一颗黑白树.允许删除一个白点.最大化删点后无法与删点前距自己最远的黑点连通的黑点个数.并求出方案数. 题解: 这道题很棒棒啊. 一开始想了一个做法,要用LCT去搞,特别麻烦而且还是\( ...
- bzoj 2395 Timeismoney —— 最小乘积生成树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2395 参考博客:https://www.cnblogs.com/autsky-jadek/p ...
- 转载 : 10大H5前端框架
原文作者: http://www.cnblogs.com/kingboy2008/p/5261771.html 作为一名做为在前端死缠烂打6年并且懒到不行的攻城士,这几年我还是阅过很多同门从知名到很知 ...
- Java程序打包成exe可执行文件
前言: 我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: ecl ...
- 使用Azure CLI实现自动关闭Azure虚拟机的脚本
Azure除提供Portal界面.PowerShell进行管理外,还提供Xplate的CLI对其进行管理. 在Azure的管理界面上可以下载各种平台的Xplate CLI的安装程序. 下面是一个小的脚 ...
- Spring boot 学习一:认识Spring boot
什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...