Home > DeveloperSection > Forums > How to check atleast one checkbox is checked?
Ankit Singh

Total Post:341

Posted on    September-02-2014 12:15 AM


 1 Reply(s)
 1086  View(s)
Rate this:

I want to check at least one checkbox should be checked before unload the page or clicking on btn save.

<asp:GridView ID="grdTest" runat="server" DataKeyNames="Id" AutoGenerateColumns="False" HorizontalAlign="Center" GridLines="None" onrowcreated="grdTest_RowCreated">

  <asp:TemplateField >


        <asp:TextBox ID="txtText" Rows="10" Columns="40" runat="server" TextMode="MultiLine"   Height="55px" Text='<%# Eval("Text") %>'></asp:TextBox>

        <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save"/>           

        <span id="checkbox">

        <asp:RadioButton ID="rbtnTest"  runat="server" Checked='<%# Eval("Correct") %>' TextAlign="Left"  Height="28px" />




        <asp:TextBox ID="txtText" Rows="10" Columns="40" runat="server" TextMode="MultiLine" />

        <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save"/>

        <asp:CheckBox ID="rbtnTest" runat="server"  Enabled="true" TextAlign="Left"/>




plz some one help me?

Sumit Kesarwani

Total Post:378

Posted on    September-02-2014 12:42 AM

Hi Ankit, 
try this:

<script type="text/javascript" language="javascript">

function Validate_Checkbox()


    var chks=document.getElementsByTagName('input');  

    var hasChecked = false;

    for (var i = 0; i < chks.length; i++)


            if (chks[i].checked)


                    hasChecked = true;




      if (hasChecked == false)


                alert("Please select at least one checkbox..!");

                return false;


            return true;



and on Submit Button you have to write

OnClientClick="return Validate_Checkbox()"

Don't want to miss updates? Please click the below button!

Follow MindStick