ASP.NET验证控件CustomValidator客户端验证DropDownList、TextBox
<asp:DropDownList ID="ddlTown" runat="server">
<asp:ListItem Value="-1">---选择乡镇---</asp:ListItem>
<asp:ListItem Value="沂城街道">沂城街道</asp:ListItem>
<asp:ListItem Value="道托镇">道托镇</asp:ListItem>
<asp:ListItem Value="高桥镇">高桥镇</asp:ListItem>
<asp:ListItem Value="马站镇">马站镇</asp:ListItem>
<asp:ListItem Value="杨庄镇">杨庄镇</asp:ListItem>
<asp:ListItem Value="富官庄镇">富官庄镇</asp:ListItem>
<asp:ListItem Value="圈里乡">圈里乡</asp:ListItem>
<asp:ListItem Value="沙沟镇">沙沟镇</asp:ListItem>
<asp:ListItem Value="诸葛镇">诸葛镇</asp:ListItem>
<asp:ListItem Value="泉庄镇">泉庄镇</asp:ListItem>
<asp:ListItem Value="龙家圈镇">龙家圈镇</asp:ListItem>
<asp:ListItem Value="黄山铺镇">黄山铺镇</asp:ListItem>
<asp:ListItem Value="崔家峪">崔家峪</asp:ListItem>
<asp:ListItem Value="夏蔚镇">夏蔚镇</asp:ListItem>
<asp:ListItem Value="高庄镇">高庄镇</asp:ListItem>
<asp:ListItem Value="沂蒙风情旅游区(院东头镇)">沂蒙风情旅游区(院东头镇)</asp:ListItem>
<asp:ListItem Value="许家湖镇">许家湖镇</asp:ListItem>
<asp:ListItem Value="四十里镇">四十里镇</asp:ListItem>
<asp:ListItem Value="开发区">开发区</asp:ListItem>
</asp:DropDownList> <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="*请选择乡镇" ClientValidationFunction="ChkDropDownList" ControlToValidate="ddlTown"></asp:CustomValidator>
需要的js:
function ChkDropDownList(source, args) {
if (args.Value == "-1")//当下拉菜单选择的是-1的时候,就是没有选择
args.IsValid = false;
else
args.IsValid = true;
}
http://blog.163.com/dreamman_yx/blog/static/2652689420107542140761/
设置Dropdownlist选中:
public void selectValue(DropDownList ddl, string value)
{
foreach (ListItem item in ddl.Items)
{
if (value == item.Value)
item.Selected = true;
}
}
下拉菜单设置选中项: ddlCity.SelectedIndex = ddlCity.Items.IndexOf(ddlCity.Items.FindByText(cityname));
ASP.NET验证控件CustomValidator客户端验证DropDownList、TextBox的更多相关文章
- [转].net自定义验证控件CustomValidator的使用
本文转自:http://tech.cncms.com/web/aspnet/96310.html CustomValidator验证控件,可以自定义验证函数,实现其它几个验证控件不能实现的验证规则,最 ...
- ASP.NET开发中主要的字符验证方法-JS验证、正则表达式、验证控件、后台验证
ASP.NET开发中主要的字符验证方法-JS验证.正则表达式.验证控件.后台验证 2012年03月19日 星期一 下午 8:53 在ASP.NET开发中主要的验证方法收藏 <1>使用JS验 ...
- Js表单验证控件-02 Ajax验证
在<Js表单验证控件(使用方便,无需编码)-01使用说明>中,写了Verify.js验证控件的基本用法,基本可以满足大多数验证需求,如果涉及服务端的验证,则可以通过Ajax. Ajax验证 ...
- 在usercontrol中如何使用验证控件CustomValidator 中的客户端验证
在用户控件中,为一个文本控件添加CustomValidator验证,然后设置CustomValidator 的ClientValidationFunction 属性为客户端的Validate(sour ...
- ASP.NET_验证控件(class0620)
为什么使用验证控件 当需要让用户输入数据时,用户有可能输入不符合我们程序逻辑要求的信息,所以我们要对输入进行验证. 客户端验证(用户体验,减少服务器端压力) 服务器端验证(防止恶意攻击,客户端js很容 ...
- 016. asp.net的验证控件
RequiredFileldValidator: 检查某个字段是否输入; 空值检查 主要属性: ControlToValidate:要验证的控件 ErrorMessage:错误提示信息 Compare ...
- ASP.NET验证控件应用实例与详解。
ASP.NET公有六种验证控件,分别如下: 控件名 功能描叙 1RequiredFieldValidator(必须字段验证) 用于检查是否有输入值 2CompareValidator(比 ...
- ASP.Net 验证控件 RequiredFieldValidator
使用 ASP.NET 验证控件可在网页上检查用户输入.有用于各种不同类型验证的控件,例如范围检查或模式匹配验证控件.每个验证控件都引用网页上其他位置的输入控件(服务器控件).当处理用户输入时(例如,当 ...
- ASP.NET验证控件详解
现在ASP.NET,你不但可以轻松的实现对用户输入的验证,而且,还可以选择验证在服务器端进行还是在客户端进行,再也不必考虑那么多了,程序员们可以将重要精力放在主程序的设计上了. ASP.NET公有六种 ...
随机推荐
- 下载整个网页的方法,包括样式、图片、和js
扒别人网站,不一定是要干邪恶的事(当然也有干的).有时候我们看到别人网站的功能很酷,想要自己试着实现一下.我们就需要扒一下这个页面,一方面可以线下修改学习,另一方面不会浪费时间在设计页面上,可以更关心 ...
- hihoCoder #1055 : 刷油漆 [ 树形dp ]
传送门 结果:Accepted 提交时间:2015-05-11 10:36:08 #1055 : 刷油漆 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到 ...
- 学习日常笔记<day11>cookie及session
1.会话管理 1.1会话管理定义 会话管理:管理浏览器客户端和服务端之间的会话过程中产生的会话数据 域对象:实现资源之间的数据共享 request 域对象 context 域对象 1.2.会话技术 C ...
- 七天从零基础学习android(2)--第一个安卓程序
在环境配置的那一部分,已经把基础的环境配置好了,接下来应该实现第一个安卓程序,就是著名的hello world 先在avd里面新建一个虚拟机,并且启动它 然后该虚拟机器能够在eclipse上正常识别 ...
- ArcGIS Engine 中的绘制与编辑
1.线段绘制 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x, y); 2. 创建 IPoi ...
- 基于Hexo + Git + Nginx的博客发布
进过上一篇<树莓派搭建私人服务器>,我们已经有一个私人服务器了,现在需要做点什么实际事情了,先搭一个博客分享自己的经验吧. 相关文章:1.<树莓派搭建私人服务器>(http:/ ...
- Android NFC近场通信02----读写卡的准备工作
Android NFC近场通信02----读写卡的准备工作 因为公司接了一个听上去感觉比較NB的项目.给某油田做派工系统 .并由小女子负责Androi ...
- ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library
ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library 须要安装pcre包. sudo apt-get upd ...
- python 多线程中同步的小样例
#!/usr/bin/python # -*- coding: UTF-8 -*- # 在一个资源池中.获取资源 # Author: zhang # Date: 2015-7-27 import ti ...
- web.xml文件中各个配置的说明
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://w ...