Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's easy to do this validation server side, but I am assuming you want to do it client side?</p> <p><a href="http://jquery.com/" rel="noreferrer">JQuery</a> can do this very easily as long as you have something that all checkbox controls have in common to use as a selector such as class (CssClass on your .NET control). You can make a simple <a href="http://jquery.com/" rel="noreferrer">JQuery</a> function and connect it to a ASP.NET custom validator. Remember if you do go the custom validator route to make sure you check it server side as well in case javascript is not working, you don't get a free server side check like the other .NET validators.</p> <p>For more information on custom validators check out the following links: <a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx" rel="noreferrer">www.asp.net</a> and <a href="http://msdn.microsoft.com/en-us/library/9eee01cx.aspx" rel="noreferrer">MSDN</a></p> <p>You don't need to use <a href="http://jquery.com/" rel="noreferrer">JQuery</a>, it just makes the javascript function to iterate and look at all your checkbox controls much easier but you can just use vanilla javascript if you like.</p> <p>Here is an example I found at: <a href="http://pankajlalwani.blogspot.com/2009/05/validating-checkboxlist-using.html" rel="noreferrer">Link to original</a></p> <pre><code>&lt;asp:CheckBoxList ID="chkModuleList"runat="server" &gt; &lt;/asp:CheckBoxList&gt; &lt;asp:CustomValidator runat="server" ID="cvmodulelist" ClientValidationFunction="ValidateModuleList" ErrorMessage="Please Select Atleast one Module" &gt;&lt;/asp:CustomValidator&gt; // javascript to add to your aspx page function ValidateModuleList(source, args) { var chkListModules= document.getElementById ('&lt;%= chkModuleList.ClientID %&gt;'); var chkListinputs = chkListModules.getElementsByTagName("input"); for (var i=0;i&lt;chkListinputs .length;i++) { if (chkListinputs [i].checked) { args.IsValid = true; return; } } args.IsValid = false; } </code></pre> <p>Side Note: <a href="http://jquery.com/" rel="noreferrer">JQuery</a> is just a little js file include you need to add to your page. Once you have it included you can use all the <a href="http://jquery.com/" rel="noreferrer">JQuery</a> you like. Nothing to install and it will be full supported in the next version of Visual Studio I think.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload