I tried creating a custom validator to validate a checkbox and got this error: "Control 'cbVerify' referenced by the ControlToValidate property of 'CustomValidator1' cannot be validated."
Here is the front end code i have for this:
<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>
Back end:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = cbVerify.Checked ;
}
Could i get some help figuring this out?
Remove the ControlTovalidate value from CustomValidator1. it does not need to be there for checkboxes.
MSDN reference
Use the ControlToValidate property to specify the input control to validate. This property must be set to the ID of an input control for all validation controls except the CustomValidator control, which can be left blank. If you do not specify a valid input control, an exception will be thrown when the page is rendered. The ID must refer to a control within the same container as the validation control. It must be in the same page or user control, or it must be in the same template of a templated control. The standard controls that can be validated are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With