title: validate checkbox asp.net c#
body: <p>I am trying to validate two checkboxes. One of them must be checked in order for the form to be valid. I would like to use a CustomValidator control, and validate on the server.</p>
  <p>(This .ascx page is a form that is displayed on a different .aspx page.)</p>
  <p>First I put in the checkboxes and a CustomValidator control on my .ascx page. Like this:</p>
  <pre><code>&lt;tr&gt;
          &lt;td colspan=&quot;3&quot;&gt;
              &lt;input type=&quot;checkbox&quot; runat=&quot;server&quot; name=&quot;EmailCourse&quot; class=&quot;&quot; id=&quot;EmailCourse&quot; value=&quot;&quot; /&gt;
                  Email course
  &lt;asp:CustomValidator id=&quot;CustomValidator1&quot; runat=&quot;server&quot; ErrorMessage=&quot;No checkbox checked&quot; 
                   OnServerValidate=&quot;validateCheckBoxes_ServerValidate&quot;&gt;
                  &lt;/asp:CustomValidator&gt;
  
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;tr&gt;
          &lt;td colspan=&quot;3&quot;&gt;
              &lt;input type=&quot;checkbox&quot; runat=&quot;server&quot; name=&quot;SpecialReport&quot; class=&quot;&quot; id=&quot;SpecialReport&quot;  value=&quot;&quot; /&gt;
                  Special report
          &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  <p>Then, I added the validateCheckBoxes_ServerValidate function in the code-behind, on the .ascx.cs page, like this:</p>
  <pre><code>            protected void validateCheckBoxes_ServerValidate(object source, ServerValidateEventArgs args)
          {
              if (!EmailCourse.Checked &amp;&amp; !SpecialReport.Checked)
                  args.IsValid = false;
              else
                  args.IsValid = true;
  
      }
  </code></pre>
  <p>When I try to open the page that uses this form on my local site to see what it looks like, I get an error, like this:</p>
  <blockquote>
  <p>Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.</p>
  <p>Compiler Error Message: CS1061: 'ASP.common_controls_specialreportform_ascx' does not contain a definition for 'validateCheckBoxes_ServerValidate' and no extension method 'validateCheckBoxes_ServerValidate' accepting a first argument of type
  'ASP.common_controls_specialreportform_ascx' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  <p>And:</p>
  <blockquote>
  <p>error CS1061: 'ASP.common_controls_specialreportform_ascx' does not contain a definition for 'validateCheckBoxes_ServerValidate' and no extension method 'validateCheckBoxes_ServerValidate' accepting a first argument of type 'ASP.common_controls_specialreportform_ascx' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  <p>Does anyone know what the cause of this error is? I'm new at asp.net and am having trouble with this.</p>
  <p>Thanks!</p>