带有 ValidationSummary 的复选框自定义验证器不起作用

发布于 2024-10-14 07:27:21 字数 1000 浏览 8 评论 0原文

我有以下验证,该验证对于我的其余字段工作正常,但尝试让自定义验证器作为复选框验证摘要的一部分工作,但没有乐趣。

这就是我现在所拥有的,

<script language="javascript" type="text/javascript">
function ValidateTandCs(source, args)
{
    args.IsValid = document.getElementById('<%= optIn.ClientID %>').checked;
}
</script>

<asp:ValidationSummary CssClass="highlight"
    id="ValidationSummary1" 
     HeaderText="<p>Please amend these errors below to continue with your 
         application.</p>" Runat="server" />

<asp:CheckBox id="optIn" runat="server"></asp:CheckBox> I agree to the terms and 
               conditions of this site and I wish to Opt In for registration.
<asp:CustomValidator ID="valTandCs" ClientValidationFunction="ValidateTandCs" 
     ValidationGroup="ValidationSummary1" runat="server" 
     ErrorMessage="Please accept Terms and Conditions before submitting.">
</asp:CustomValidator>

但是当我单击“提交”时,我只看到其他字段的错误消息,而此复选框没有任何内容......有什么想法吗?

I have the following validation which is working fine for the rest of my fields, but trying to get a custom validator to work as part of the validation summary for a checkbox but no joy.

This is what I have at the moment

<script language="javascript" type="text/javascript">
function ValidateTandCs(source, args)
{
    args.IsValid = document.getElementById('<%= optIn.ClientID %>').checked;
}
</script>

<asp:ValidationSummary CssClass="highlight"
    id="ValidationSummary1" 
     HeaderText="<p>Please amend these errors below to continue with your 
         application.</p>" Runat="server" />

<asp:CheckBox id="optIn" runat="server"></asp:CheckBox> I agree to the terms and 
               conditions of this site and I wish to Opt In for registration.
<asp:CustomValidator ID="valTandCs" ClientValidationFunction="ValidateTandCs" 
     ValidationGroup="ValidationSummary1" runat="server" 
     ErrorMessage="Please accept Terms and Conditions before submitting.">
</asp:CustomValidator>

But when I click submit I only see the error messages for my other fields and nothing for this checkbox...any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2024-10-21 07:27:21

您的代码中有这样的内容:

 document.getElementById('<%= optIn.ClientID %><%= optIn.ClientID %>').checked;

将其更改为:

 document.getElementById('<%= optIn.ClientID %>').checked;

同时为 CustomValidator 设置 ControlToValidate 属性:

<asp:CustomValidator ID="valTandCs" ClientValidationFunction="ValidateTandCs" 
 ControlToValidate="optIn" //
 ValidationGroup="ValidationSummary1" runat="server" 

You had this in your code:

 document.getElementById('<%= optIn.ClientID %><%= optIn.ClientID %>').checked;

change it to:

 document.getElementById('<%= optIn.ClientID %>').checked;

Also set ControlToValidate property for CustomValidator:

<asp:CustomValidator ID="valTandCs" ClientValidationFunction="ValidateTandCs" 
 ControlToValidate="optIn" //
 ValidationGroup="ValidationSummary1" runat="server" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文