如何使用Asp.net验证复选框 [英] How to Validate checkBox using Asp.net

查看:103
本文介绍了如何使用Asp.net验证复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Asp.net验证复选框

How to Validate checkBox using Asp.net

推荐答案

请参见以下链接:-

see the below link:-

Using Custom Validator to Validate Checkbox[^]



用于客户端验证的javascript函数(使用jQuery).
Hi,
javascript function for client side validation (using jQuery).
function CheckBoxRequired_ClientValidate(sender, e)
{
    e.IsValid = jQuery(".AcceptedAgreement input:checkbox").is(':checked');
}


用于服务器端验证的代码隐藏...


Code-behind for server side validation...

protected void CheckBoxRequired_ServerValidate(object sender, ServerValidateEventArgs e)
{
    e.IsValid = MyCheckBox.Checked;
}


复选框&的ASP.Net代码验证器..


ASP.Net code for the checkbox & validator..

<asp:CheckBox runat="server" ID="MyCheckBox" CssClass="AcceptedAgreement" />
<asp:CustomValidator runat="server" ID="CheckBoxRequired" EnableClientScript="true"

    OnServerValidate="CheckBoxRequired_ServerValidate"

    ClientValidationFunction="CheckBoxRequired_ClientValidate">You must select this box to proceed.</asp:CustomValidator>


最后,在您的回发中-无论是通过按钮还是其他方式...


And finally, in your postback - whether from a button or whatever...

if (Page.IsValid)
{
    // your code here...
}


希望对您有所帮助.

--Amit


I hope it''ll help you.

--Amit


这篇关于如何使用Asp.net验证复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆