Onlineatoz.net | ToolBox Standard Control RadioButton

ToolBox Standard Control RadioButton

RadioButton Web Server Control

in ASP.NET environment,This article explains you how to work with RadioButton Web Control.ASP.NET provides two controls such as RadioButton and RadioButtonList.The RadioButton and RadioButtonList Web server controls provide a way for users to select exclusive options.

here, two Controls provide differnt functions and can be used to achive different purposes.The controls allow you to define any number of radio buttons with labels and to arrange them horizontally or vertically.

RadioButton Vs RadioButtonList

Individual RadioButton control to a page provides a single options to a page.for more options,we include more than one RadioButtons

In other hand, the RadioButtonList control is a single control that acts as a parent control for a collection of radio button list items.Therefore, many of the procedures for working with the RadioButtonList control are the same as they are for the other list Web server controls.

Grouping Radio Buttons

The following ways helps you to create grouped Radio Buttons

  • Add individual RadioButton Web server controls to a page and then manually assign them all to a group. In this case, the group is an arbitrary name; all radio buttons with the same group name are considered part of a single group.
  • Add a RadioButtonList Web server control to the page. The list items in the control are automatically grouped.
Radio Button Events

RadioButton controls perfomes a CheckedChanged event when users click the control. By default, this event does not cause the page to be posted to the server, but you can have the control force an immediate post by setting the AutoPostBack property to true

To add a RadioButton control to a page
  • Type an <asp:RadioButton> element in the page.
  • then You must want to set the Id and runat properteis of PlaceHolder Web Control
  • Optionally,set the GroupName propery when more than one Radiobutton has used that specify whether all the Radio buttons are in a similar Group or not
To add a RadioButtonList control to a page
  • Type an <asp:RadioButtonList> element in the page.
  • then You must want to set the Id and runat properteis of PlaceHolder Web Control
  • Type <asp:ListItem> into the RadioButtonList control, as described earlier,we can add Text,Value and Selected property to the ListItem control

the following code snippets demonstrates Add Property to a RadioButtonList control Programmatically.

in .aspx.cs page,

RadioButton1.InputAttributes.Add("onmouseover", 
"this.style.backgroundColor = 'red'");
RadioButton1.InputAttributes.Add("onmouseout",
"this.style.backgroundColor = 'white'");
Respond to a User Selection in a RadioButton

When an User select a RadionButton,then event raises in RadioButton control.You respond to the event only if it is important to know when the user has made a change to the selection in a radio button group.

To respond to a selection in a RadioButton control

  • Create an event handler for the control's CheckedChanged event.

the following code snippets demonstrates Responds to a RadioButtonList control event Programmatically.

in .aspx.cs page,

public void RadioButton1_CheckedChanged (object sender, 
System.EventArgs e)
{
Label1.Text = "You selected Radio Button " + RadioButton1.Text;
}
 
Related Links

Posted by: Admin
Posted on: 9/13/2011 at 2:00 PM
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed