我尝试创建自定义验证器来验证复选框并收到此错误:“无法验证由‘CustomValidator1’的 ControlToValidate 属性引用的控件‘cbVerify’。”
这是我为此准备的前端代码:
<li>
<asp:CheckBox ID="cbVerify" runat="server" Text="I certify that the information entered on this form is correct and accurate." />
</li>
<li>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please check" Display="Dynamic" ControlToValidate="cbVerify" OnServerValidate="CustomValidator1_ServerValidate" CssClass="ValidationError"></asp:CustomValidator>
</li>
后端:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = cbVerify.Checked ;
}
我能得到一些帮助来解决这个问题吗?