【发布时间】:2019-09-18 13:59:12
【问题描述】:
我有一个Telerik:RadListView 控件和多个复选框。我需要在提交表单之前验证这些复选框。
我尝试了带有ControlToValidate 属性的内置验证器,但它给了我错误Control 'chkQuestion' referenced by the ControlToValidate property of 'chkQuestionValidator' cannot be validated.,这是非常合乎逻辑的,因为它们都在RadListView 中。
之后,我创建了一个 CustomValidator;
<asp:CheckBox ID="chkQuestion"
CssClass="AcceptedAgreement"
Visible="true"
runat="server"
Text=" I confirm"
AutoPostBack="false" />
<asp:CustomValidator
ClientValidationFunction="CheckBoxRequired_ClientValidate"
EnableClientScript="true"
ID="chkQuestionValidator"
runat="server"
Enabled="true"
SetFocusOnError="true"
ErrorMessage="Please confirm"
ForeColor="Red" />
这些都在Telerik:RadListView 中,这意味着我有多个,但我无法在我的客户端自定义验证器函数中链接它们。
这是我的验证器函数:
function CheckBoxRequired_ClientValidate(sender, e) {
var c = jQuery(".AcceptedAgreement input:checkbox");
var chb = validator
if (c.is(':checked')) {
e.IsValid = true;
} else {
e.IsValid = false;
}
}
但使用此功能,我无法单独验证它们。 when one of the checkboxes checked, this function act like all of them are checked.这是因为它们都有相同的 css 类,这就是我坚持的重点。
如果你能帮助我,我们将不胜感激。
【问题讨论】:
标签: javascript c# asp.net webforms