title: Need a better way to validate ASP.NET checkboxes using a jquery validation plugin?
body: <p><strong>Problem:</strong></p>
  
  <p>I want to validate some ASP.NET-checkboxes using the jquery validation plugin (found at: <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">http://bassistance.de/jquery-plugins/jquery-plugin-validation/</a>)</p>
  
  <p><strong>What it's all about:</strong></p>
  
  <p>It's not possible to set the name attribute of ASP.NET checkboxes (or is it?). It'll automatically be set, when the control is rendered and can be retrieved using</p>
  
  <pre><code>&lt;%= emailCheckBox.UniqueID %&gt;
  </code></pre>
  
  <p>So two checkboxes as the following:</p>
  
  <pre><code>&lt;asp:CheckBox runat="server" ID="emailAcceptCheckBox" /&gt;Email&lt;br /&gt;
  &lt;asp:CheckBox runat="server" ID="phoneAcceptCheckBox" /&gt;Phone&lt;br /&gt;
  </code></pre>
  
  <p>will render to:</p>
  
  <pre><code>&lt;INPUT id="ctl00_MainContentPlaceHolder_emailAcceptCheckBox" type="checkbox" name="ctl00$MainContentPlaceHolder$emailAcceptCheckBox"&gt;
  &lt;INPUT id="ctl00_MainContentPlaceHolder_phoneAcceptCheckBox" type="checkbox" name="ctl00$MainContentPlaceHolder$phoneAcceptCheckBox"&gt;
  </code></pre>
  
  <p>Maybe it's a mess to mix ASP.NET with the jquery validation plugin, but I prefer the jquery validation plugin and it works fine with inputs and other fields.</p>
  
  <p>Problem is, that the jquery validation plugin wants to group the checkboxes using the name-attribute of checkboxes. This name attributes should be equal to all checkboxes and a group.</p>
  
  <p><strong>What I've done:</strong></p>
  
  <p>I added a rule to ALL checkboxes using jquery:</p>
  
  <pre><code>$("#[id*='AcceptCheckBox']").each(function() { $(this).rules("add", { minchecked: 1 }); });
  </code></pre>
  
  <p>And added my own rule checking for checkboxes:</p>
  
  <pre><code>jQuery.validator.addMethod("minchecked",
   function(value, element, param) {
       var noOfChecked = $("#[id*='AcceptCheckBox']:checked").length;
            return noOfChecked &gt;= param;
       },
   "Error");
  </code></pre>
  
  <p>(This rule will apply for checkboxes whose IDs include AcceptCheckBox, but it's okay in this example).</p>
  
  <p>When I call:</p>
  
  <pre><code>var result = $("#aspnetForm").validate().form();
  </code></pre>
  
  <p>It returns perfectly if my validation succeeded or failed!</p>
  
  <p>BUT:</p>
  
  <p>1) I don't feel that this is a very clean and nice solution. Any better advice?</p>
  
  <p>2) When I run validate().form() it'll go through ALL my checkboxes and for each of them check all the other checkboxes. That's really not necessary. How can I avoid this?</p>