<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的更多相关文章

  1. [转].net自定义验证控件CustomValidator的使用

    本文转自:http://tech.cncms.com/web/aspnet/96310.html CustomValidator验证控件,可以自定义验证函数,实现其它几个验证控件不能实现的验证规则,最 ...

  2. ASP.NET开发中主要的字符验证方法-JS验证、正则表达式、验证控件、后台验证

    ASP.NET开发中主要的字符验证方法-JS验证.正则表达式.验证控件.后台验证 2012年03月19日 星期一 下午 8:53 在ASP.NET开发中主要的验证方法收藏 <1>使用JS验 ...

  3. Js表单验证控件-02 Ajax验证

    在<Js表单验证控件(使用方便,无需编码)-01使用说明>中,写了Verify.js验证控件的基本用法,基本可以满足大多数验证需求,如果涉及服务端的验证,则可以通过Ajax. Ajax验证 ...

  4. 在usercontrol中如何使用验证控件CustomValidator 中的客户端验证

    在用户控件中,为一个文本控件添加CustomValidator验证,然后设置CustomValidator 的ClientValidationFunction 属性为客户端的Validate(sour ...

  5. ASP.NET_验证控件(class0620)

    为什么使用验证控件 当需要让用户输入数据时,用户有可能输入不符合我们程序逻辑要求的信息,所以我们要对输入进行验证. 客户端验证(用户体验,减少服务器端压力) 服务器端验证(防止恶意攻击,客户端js很容 ...

  6. 016. asp.net的验证控件

    RequiredFileldValidator: 检查某个字段是否输入; 空值检查 主要属性: ControlToValidate:要验证的控件 ErrorMessage:错误提示信息 Compare ...

  7. ASP.NET验证控件应用实例与详解。

    ASP.NET公有六种验证控件,分别如下:  控件名      功能描叙 1RequiredFieldValidator(必须字段验证)  用于检查是否有输入值 2CompareValidator(比 ...

  8. ASP.Net 验证控件 RequiredFieldValidator

    使用 ASP.NET 验证控件可在网页上检查用户输入.有用于各种不同类型验证的控件,例如范围检查或模式匹配验证控件.每个验证控件都引用网页上其他位置的输入控件(服务器控件).当处理用户输入时(例如,当 ...

  9. ASP.NET验证控件详解

    现在ASP.NET,你不但可以轻松的实现对用户输入的验证,而且,还可以选择验证在服务器端进行还是在客户端进行,再也不必考虑那么多了,程序员们可以将重要精力放在主程序的设计上了. ASP.NET公有六种 ...

随机推荐

  1. 《TCP/IP详解卷1:协议》——第6章 ICMP:Internet控制报文协议(转载)

    1.引言 ICMP被认为是IP层的一个组成部分,它传递差错报文以及其他需要注意的信息.ICMP报文通常被IP层或更高层协议(TCP或UDP)使用.一些ICMP报文把差错报文返回给用户进程. ICMP报 ...

  2. angularjs ngRoute的使用简单例子

    很丑的小例子,刚学angularjs,写下来方面以后看. 1.例子的工程目录如下: 2.index.html代码如下: <!DOCTYPE html><html><hea ...

  3. POJ 1470 Closest Common Ancestors【LCA Tarjan】

    题目链接: http://poj.org/problem?id=1470 题意: 给定若干有向边,构成有根数,给定若干查询,求每个查询的结点的LCA出现次数. 分析: 还是很裸的tarjan的LCA. ...

  4. 继续畅通工程--hdu1879(最小生成树 模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1879 刚开始么看清题  以为就是n行  后来一看是n*(n-1)/2行   是输入错误  真是够够的 #incl ...

  5. [Noip复习知识点][个人向]Zackzh

    只是列列一些要复习的,努力复习吧,有种noip退役的赶脚. 一.模拟 (这你也不会?退役吧) 二.DP 1.基础dp 2.区间dp 3.状压dp 4.树形dp 6.概率(期望)dp 7.环形dp 8. ...

  6. try catch finally执行顺序 (return / 变量覆盖)

    finally有return 始终返回finally中的return 抛弃 try 与catch中的return 情况1:try{} catch(){}finally{} return x; try{ ...

  7. python执行

    转载:https://www.cnblogs.com/zflibra/p/4180796.html

  8. 【Nginx】Nginx事件模块

    一.事件处理框架概述 事件处理框架所要解决的问题是如何收集.管理.分发事件.事件以网络事件和定时器事件为主,而网络事件中以TCP网络事件为主.事件处理框架需要在不同的操作系统内核中选择一种事件驱动机制 ...

  9. Linux 快照

    10个方法助你轻松完成Linux系统恢复 提交 我的留言 加载中 已留言 这也就是为什么系统恢复功能会让人感觉如此神奇.你可以很快地重新回到工作中去,就像什么事情都没有发生一样,也不用去管造成系统故障 ...

  10. Friefox清除旧的网页缓存

    Ctrl + F5 适用于调试网页编码时,不断以旧设置显示页面