您的位置:首页 > 其它

【记录】自定义服务器验证控件

2013-11-02 16:56 309 查看
<asp:CheckBoxList ID="ck1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="2">街道办用户</asp:ListItem>
<asp:ListItem Value="3">社区用户</asp:ListItem>
<asp:ListItem Value="4">培训机构用户</asp:ListItem>
<asp:ListItem Value="5">学员用户</asp:ListItem>
</asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ClientValidate"
Display="Dynamic" ErrorMessage="请至少选择一个"></asp:CustomValidator>


自定义验证控件

function  ClientValidate(sender, args)
{
var flag = false;
var radioList=document.getElementById("ck1");
var inarr = radioList.getElementsByTagName('input');
for (var i=0; i<inarr.length; i++)
{
if(inarr[i].type=="checkbox")
{
if(inarr[i].checked==true)
{
flag = true;
}
}
}
if (flag)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐