RadioButton control
You can use two types of ASP.NET controls to add radio buttons to a page: individual RadioButton controls or a RadioButtonList control. Both controls allow users to select from a small set of mutually exclusive, predefined choices. The controls allow you to define any number of radio buttons with labels and to arrange them horizontally or vertically. For a comparison of RadioButton and RadioButtonList controls, see RadioButtonList control.
To add a RadioButton control to a page
-
Drag the RadioButton control from the Toolbox task pane to your page.
-
Set properties for the control in the Tag Properties task pane.
Common RadioButton Properties
|
Property |
Description |
|---|---|
|
Text |
Specifies the label text displayed beside the radio button. |
|
GroupName |
Specifies the name of the group that the radio button belongs to. Only one radio button at a time can be selected in a group. |
For a full description of all RadioButton control properties, see RadioButton Properties in the MSDN library.
When the RadioButton control renders to the browser, it does so in two parts: an <input> element representing the radio button, and a separate <label> element representing the caption for the radio button. The combination of the two elements is in turn wrapped in a <span> element.
When you apply style or attribute settings to a RadioButton control, they are applied to the outer <span> element. For example, if you set the control's BackColor property, the setting is applied to the <span> tag, and therefore affects both the inner <input> and <label> elements.
At times, you might want to be able to make separate settings for the radio button and the label. The RadioButton control supports two properties that you can set at run time: the InputAttributes property and the LabelAttributes property. Each property allows you to add HTML attributes to the <input> and <label> elements, respectively. The attributes you set are passed through as-is to the browser.