Showing posts with label Radio Button Control. Show all posts
Showing posts with label Radio Button Control. Show all posts

RadioButton Control



This Control is used to provide selection of only one option from the given group of options

Properties with Radio Button Control:
  1. AutoPostBack(options[True/False(Default)])                                                                     
  2.  Checked(options:[True/False(Default)])                                         
  3. GroupName
1)CheckedProperty:
  • This property stores true when Radio Button is activated
  • Stores false when Radio Button is deactivated or deselected
2)AutoPostBack:
  • When set to true request of the page will be submitted as PostBack to the WebServer, when default Event is fired
  • False: page request will not be submitted or post back to web server, when default Event is fired
3)GroupName:
  • Used to give common or same name for the group of Radio Button so that user can be allowed to select any one from the group
Default Event of RadioButton:
  • CheckedChanged: Is the default Event of Radio Button Control, this Event will be fired when checked properties changes from true to false (or) false to true
Example with RadiButton Control:--
   
Create a New WebPage ,Design the web page 



  • Set the following properties
  • Set Group name as  BColor  & AutoPostPack as true for all RadioButtons
  • Type in Radio Buttons text as Red,Green
  • Set ID’s for Radio Buttons as for Red optRed,for Green optGreen, for white optwhite
  • Set label text as Enter any data & ID as lblsample
  • Set Text Box1 ID as txtSample
  • Incluse NameSpace as using System.Drawing;
  • Goto Source and write the following codeCheckedCahnged Events of the RadioButtons.
Source and write the following codeCheckedCahnged Events of the RadioButtons.

protected void optRed_CheckedChanged(object sender, EventArgs e)
{
        txtSample.BackColor = Color.Red;
}
protected void optGreen_CheckedChanged(object sender, EventArgs e)
{
        txtSample.BackColor = Color.Green;
}

Run the WebPage & Check