Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to validate a radio button by clientside in asp.net c#
Posted
Comments
thams 4-May-12 7:14am    
in client side how can you use c#?
You have to do it in java script or like scripts.

hi assumed that you have two radio buttons

HTML
<div>
    <input type="radio" id="radioMale" name="test"/>Male<br />
    <input type="radio" id="radioFemale" name="test"/>Female
    <br />
    <input type="button" value="Test!" id="btnTest" onclick="GetGender();"/>
</div>


and now on button click

JavaScript
function GetGender(){
        if ($('#radioMale').is(':checked')) {
            alert('Gender is Male');
        }
        if ($('#radioFemale').is(':checked')) {
            alert('Gender is Female');
        }
}
 
Share this answer
 
v2
hi,

it will show how to validate radio button with example

http://www.esqsoft.com/javascript/javascript-example-how-to-validate-radio-buttons.htm[^]
 
Share this answer
 
On aspx page
head section :
XML
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function CheckRadioButton() {
            var yes = document.getElementById("yes");
            var no = document.getElementById("no");
            if (yes.checked == true) {
                alert("yes");
            }
            if (no.checked == true) {
                alert("no");
            }

        }
    </script>
</head>


body section:-

XML
<asp:RadioButton ID="yes" runat="server" GroupName="same" Checked="true" />
   <asp:RadioButton ID="no" runat="server" GroupName="same" />
   <asp:Button ID="chk" runat="server" Text="check" OnClientClick="CheckRadioButton()" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900