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公有六种 ...
随机推荐
- ajax请求数据之后在已经有的数据前面打对勾的方法
今天遇到这么一个需求: 选择一部分人,在点击确定的时候添加到对应的div中,也就是添加到对应的表单下面,当再次查询的时候需要在已经选过的人的复选框前面打伤对勾.
- http_load分析(转)
http://www.cnblogs.com/xuning/p/3954057.html 一.前言 http_load是一款测试web服务器性能的开源工具,从下面的网址可以下载到最新版本的http_l ...
- Spring Boot中实现logback多环境日志配置
在Spring Boot中,可以在logback.xml中的springProfile标签中定义多个环境logback.xml: <springProfile name="produc ...
- Random Forest 与 GBDT 的异同
曾经在看用RF和GBDT的时候,以为是非常相似的两个算法,都是属于集成算法,可是细致研究之后,发现他们根本全然不同. 以下总结基本的一些不同点 Random Forest: bagging (你懂得. ...
- Deepin-安装laravel
首先获取到composer.phar wget https://getcomposer.org/download/1.6.3/composer.phar 下载以后移动到目标区域 sudo mv com ...
- 【Mongodb教程 第一课补加课2 】MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
如图,如果通过下列代码,添加服务后,使用net start命令出现这样的问题时,可以参考下我的解决方法. D:\MongoDB>mongod --dbpath D:\MongoDB\Data - ...
- PHP开发者实用的代码
一.查看邮件是否已被阅读 当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读.这里有段非常有趣的代码片段能够显示对方IP地址记录阅读的实际日期和时间. <? error_reporting( ...
- hdu4941 Magical Forest
Problem Description There is a forest can be seen as N * M grid. In this forest, there is some magic ...
- PHP使用debug_backtrace方法跟踪代码调用
在开发过程中,例如要修改别人开发的代码或调试出问题的代码,需要对代码流程一步步去跟踪,找到出问题的地方进行修改.如果有一个方法可以获取到某段代码是被哪个方法调用,并能一直回溯到最开始调用的地方(包括调 ...
- 反混淆、反编译unity3d动画插件DFTweenLite得到源代码
出处:http://blog.csdn.net/u010019717 author:孙广东 时间:2015.3.17 23:00 我为什么要得到这个源代码.由于有洁癖! 对于Itween ...