ASP.NET验证控件CustomValidator客户端验证DropDownList、TextBox
2013-10-16 17:03
501 查看
<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
- ASP.NET验证控件CustomValidator客户端验证DROPDOWNLIST、TEXTBOX
- [ASP.NET]为什么CustomValidator验证控件在验证DropdownList的时候不能设置ControlToValidate属性
- ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList
- Js触发ASP.NET Validation控件的验证, 同时获取前台验证结果(不包括CustomValidator)
- Asp.net自定义验证控件CustomValidator 的使用方法
- js 获取 asp.net 服务器端控件 Label 与 TextBox RadioButtonList 与 DropDownList 的值
- 以编程方式向 ASP.NET 控件添加客户端事件处理程序--TextBox.Attributes.Add()
- ASP.NET - ASP.NET 服务器控件验证类型 - CustomValidator 类
- ASP.NET验证控件与客户端脚本的一点小冲突
- ASP.NET jQuery 食谱15 (通过控件CustomValidator验证CheckBoxList)
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
- Asp.net如何验证TextBox控件只输入数字(五种情况分析)转帖
- 利用反射实现ASP.NET控件和数据实体之间的双向绑定,并且在客户端自动验证输入的内容是否合法
- CustomValidator ASP.NET验证控件
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
- ASP.NET c# textbox 正则表达式 文本框只允许输入数字(验证控件RegularExpressionValidator )
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
- Asp.net如何验证TextBox控件只输入数字(五种情况分析)转帖
- ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList