Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Validator Error

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?

like image 625
Paradigm Avatar asked Aug 02 '13 19:08

Paradigm


1 Answers

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:

  • System.Web.UI.WebControls.DropDownList
  • System.Web.UI.WebControls.FileUpload
  • System.Web.UI.WebControls.ListBox
  • System.Web.UI.WebControls.RadioButtonList
  • System.Web.UI.WebControls.TextBox
  • System.Web.UI.HtmlControls.HtmlInputFile
  • System.Web.UI.HtmlControls.HtmlInputPassword
  • System.Web.UI.HtmlControls.HtmlInputText
  • System.Web.UI.HtmlControls.HtmlSelect
  • System.Web.UI.HtmlControls.HtmlTextArea
like image 174
Mike Ramsey Avatar answered Oct 21 '22 16:10

Mike Ramsey