<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. Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]

    传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. memcached 笔记之windows 7 下面 安装memcached 报错

    windows 7 下面 安装memcached 报错 两种情况: 一:服务确实已经安装过 .如需要重新安装,当然是先memcached.exe -d uninstall 二:奇怪的是服务确实没有安装 ...

  3. linux date 格式化时间和日期

    [root@108test ~]# date -d today +"%Y-%m-%d" 2008-05-07   [root@108test ~]# date -d today + ...

  4. hdu - 5007 Post Robot (水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5007 #include<iostream> #include<stdio.h> #inc ...

  5. 洛谷—— P1977 出租车拼车

    https://www.luogu.org/problem/show?pid=1977 题目背景 话说小 x 有一次去参加比赛,虽然学校离比赛地点不太远,但小 x 还是想坐 出租车去.大学城的出租车总 ...

  6. Swift初体验之HelloWord+苹果Swift编程语言新手教程【中文版】

    AppDelegate.swift : <span style="font-size:24px;"><strong>// // AppDelegate.sw ...

  7. Meteor模板

    Meteor模板使用三个顶级标签.前两个是 head 和 body 标签.这些标签和在普通的HTML中做的工作一样.第三个标签 template.这是我们将HTML连接到JavaScript的地方. ...

  8. Ribbon简介

    Ribbon简介

  9. 盘点UML中的四种关系

    生活中,我们既是独立的个体,又通过联系形成各种关系,比方说:朋友.恋人.父子,同学--于是乎,出现了神乎其神的六人定律. 那么在UML中又存在什么样的关系呢?以下我们来梳理一下. 关联(Associa ...

  10. [LeetCode][Java] Roman to Integer

    题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...