ASP.NET Syntax ASP.NET Syntax for Web Controls
Creates an individual radio button on the page. You can group multiple radio buttons to present mutually exclusive choices.
Declarative Syntax
<asp:RadioButton
AccessKey = "string"
AutoPostBack = "True | False"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
CausesValidation = "True | False"
Checked = "True | False"
CssClass = "string"
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
Font-Bold = "True | False"
Font-Italic = "True | False"
Font-Names = "string"
Font-Overline = "True | False"
Font-Size = "string | Smaller | Larger | XX-Small | X-Small | Small |
Medium | Large | X-Large | XX-Large"
Font-Strikeout = "True | False"
Font-Underline = "True | False"
ForeColor = "color name | #dddddd"
GroupName = "string"
Height = size
ID = "string"
OnCheckedChanged = "CheckedChanged event handler"
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnUnload = "Unload event handler"
runat = "server"
SkinID = "string"
Style = "string"
TabIndex = integer
Text = "string"
TextAlign = "Left | Right"
ToolTip = "string"
ValidationGroup = "string"
Visible = "True | False"
Width = size
/>
NOTE: The content of an <asp:RadioButton
> control can be defined within its opening tag. In this case, you can close the start tag with a trailing slash />
instead of using a separate end tag.
For information on the individual members of this class, see RadioButton in the class library.
The RadioButton control renders a radio button on a Web Forms page. You can group multiple radio buttons together if you specify the same GroupName for each RadioButton control. Grouping radio buttons together will only allow a mutually exclusive selection from the group.
NOTE: You can also use the RadioButtonList control. The RadioButtonList control is easier for creating a set of radio buttons using data binding, while the individual RadioButton control gives you greater control over layout.
The below code snippet demonstrates how to use a RadioButton control.
Within the <head
> of a Web Forms page:
<script language="C#" runat="server">
string [ ] answers = {
"Abraham Lincoln came a tad bit later.",
"Christopher Columbus was an explorer, <br>not a United States President.",
"Correct. George Washington was the first President <br>of the United States of America.",
"Robert Plant was the lead vocalist of Led Zeppelin, <br>not a United States President."};
void chkAnswer ( Object Sender, EventArgs e ) {
string msg;
if ( Radio1.Checked )
msg = answers [ 0 ];
else if ( Radio2.Checked )
msg = answers [ 1 ];
else if ( Radio3.Checked )
msg = answers [ 2 ];
else if ( Radio4.Checked )
msg = answers [ 3 ];
Message.InnerHtml = msg;
}
</script>
<script language="VB" runat="server">
Dim answers ( ) As String = {
"Abraham Lincoln came a tad bit later.",
"Christopher Columbus was an explorer, <br>not a United States President.",
"Correct. George Washington was the first President <br>of the United States of America.",
"Robert Plant was the lead vocalist of Led Zeppelin, <br>not a United States President."}
sub chkAnswer ( Object Sender, EventArgs e ) {
Dim msg As String;
if Radio1.Checked then
msg = answers ( 0 );
else if ( Radio2.Checked ) then
msg = answers ( 1 );
else if ( Radio3.Checked ) then
msg = answers ( 2 );
else if ( Radio4.Checked ) then
msg = answers ( 3 );
Message.InnerHtml = msg;
}
</script> |
|
C# |
VB |
Within the <body
> of a Web Forms page:
<form runat="server">
<h5>The first president of the United States was:</h5>
<table>
<tr><td>
<asp:RadioButton id="Radio1" Text = "Abraham Lincoln"
GroupName = "choices" runat="server" />
<br>
<asp:RadioButton id="Radio2" Text = "Christopher Columbus"
GroupName = "choices" runat="server" />
<br>
<asp:RadioButton id="Radio3" Text = "George Washington"
GroupName = "choices" runat="server" />
<br>
<asp:RadioButton id="Radio4" Text = "Robert Plant"
GroupName = "choices" runat="server" />
<br>
</td></tr>
</table>
<p><asp:button text = "Submit" OnClick = "chkAnswer" runat="server" />
<p id="Message" runat="server" />
</form>
RadioButton Class RadioButton and RadioButtonlist Web Server Controls