<tr>
<td height="12" align="left" class="cont">
<asp:CheckBox ID="chkacsoutreach" runat="server" />Acs Outreach </td>
</tr>
<tr>
<td height="12" align="left" class="cont">
<asp:CheckBox ID="chkaceportal" runat="server" /> Ace Portal </td>
</tr>

I took some checkboxes in the following way.I should get a message if atleast 1 checkbox is not checked and the values should not be entered into the database.This is the validation i needed.I have written the javascript code as below:but instead of 'controls[]' there should be a groupname which combines all the checkboxes.Iam not understanding what name to give here.Can any one please help me out

<script type="text/javascript" language="javascript">
function validate() { var chks = document.getElementsByName('controls[]'); var hasChecked = false; for (var i = 0; i < chks.length; i++) { if (chks[i].checked) { hasChecked = true; break; } } if (hasChecked == false) { alert("Please select at least one."); return false; } return true; } </script>

ASP.NET has a validation control that you can attach to the check boxes. What you need to use is the custom validation checkbox. I know that several of the validation controls generate client side and server side validation. I am not sure if the custom validation can does that. In any case, the server side validation will always be present.

The validation controls keep general validation off of the server until it passes the client validation. They also protect your application because if some tries to send invalid data, bypassing your form, the server side validation will be performed and the request rejected.

<script type="text/javascript" language="javascript">
                      function checkCheckBoxes() {
//Finding the controls (here chkabi,chkairmanifest)in javascript.

                          var chkabi = document.getElementById('<%=chkabi.ClientID %>');
                          var chkairmanifest = document.getElementById('<%=chkairmanifest.ClientID %>');
//checking whether the check box is checked or not.

if (chkabi.checked == false &&
                    chkairmanifest.checked == false )
{
                              alert('Select any check box!');
                              return false;
                          }
                          else { return true; }
                      }
                    </script>

You can try like this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.