.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT


RadioButton Control


Introduction :

RadioButton Control is used for selecting one (available in RadioButton List) value. That means user can be able to select only one value at a time.

RadioButton Control is used for selecting one (available in RadioButton List) value. That means user can  be able to select only one value at a time. For eg.,  it is useful for selecting the User's  Sex , Highest Qualification etc.,
ASP.NET RadioButton itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

Important Properties of Asp.NET Webserver  RadioButton control are given below. You can Set /Get these properties  at Design time or at Runtime.

AutoPostBack -  Accept Boolean Value  - If True, then page will submit to the server if the index of the RadioButton  is changed

Enabled - Accept Boolean Value- Used to Get/Set Radiobutton Enabled

Height - Accept IntergerValue  -  Used to Set/Get height of the RadioButton

GroupName - Accept String Value - Mutilple RadioButtons  in the form can be in a group, if they have same GroupName. For Eg., if you have five RadioButtons in your form and three of them have GroupName "Group1" and other two  RadioButtons have their GroupName "Group2", then the user can select only two Radionbuttons in the form.

Text - Accept String Value - Used to defined Radio Button to the user.

Width - Accept IntergerValue -  Used to set the width of the RadioButton

Events  available in Asp.Net Webserver RadioButton Control are

CheckChanged - This Event will fire when the current status of the RadioButton is changed.
Note: This event will fire only if "AutoPostBack" Property of the RadioButton is Set to "True"

Lets See an example

Your .aspx code will look like this for a WebServer Control  RadioButton

<asp:RadioButton ID="MyRadioButton" runat="server" GroupName="Group1"

            Text="2009" />

Full Html Code used in attched example

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>RadioButton Example - DotNetSpark.com</title>



    <form id="form1" runat="server">



        <asp:Label ID="lblPageMessage" runat="server" Text="RadioButton Example"></asp:Label>

        <br />

        <br />

        Current Year:<br />

        <asp:RadioButton ID="MyRadioButton" runat="server" GroupName="Group1"

            Text="2009" />

        <br />

        <asp:RadioButton ID="MyRadioButton0" runat="server" GroupName="Group1"

            Text="2010" />

        <br />

        <asp:RadioButton ID="MyRadioButton1" runat="server" GroupName="Group1"

            Text="2011" />

        <br />

        <br />

        You Are:<br />

        <asp:RadioButton ID="MyRadioButton2" runat="server" GroupName="Group2"

            Text="Male" />

        <br />

        <asp:RadioButton ID="MyRadioButton3" runat="server" GroupName="Group2"

            Text="Female" />

        <br />

        <br />

        <asp:Label ID="lblVal" runat="server"></asp:Label>






And to assign selected value of the radioButton to the label control programmatically

protected void MyRadioButton_CheckedChanged(object sender, EventArgs e)


    lblVal.TemplateControl = MyRadioButton.Checked.ToString();

Other Tutorials in the same Category:
  • CheckBoxList Control      
  • Button Control      
  • Calendar Control      
  • CheckBox Control      
  • DropDownList Control or Combobox      
  • FileUpload Control      
  • Hidden Field Control      
  • ImageButton Control      
  • Link Button Control      
  • ListBox Control      
  • Literal Control      
  • RadioButton Control      
  • RadioButtonList Control      
  • TextBox Control

    Return to Main Index Page

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend