Allows programmatic access to the HTML <input type= radio> element on the server.
Namespace:
System.Web.UI.HtmlControls
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class HtmlInputRadioButton _
Inherits HtmlInputControl _
Implements IPostBackDataHandler
Dim instance As HtmlInputRadioButton
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class HtmlInputRadioButton : HtmlInputControl,
IPostBackDataHandler
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class HtmlInputRadioButton : public HtmlInputControl,
IPostBackDataHandler
public class HtmlInputRadioButton extends HtmlInputControl implements IPostBackDataHandler
<asp:HtmlInputRadioButton />
Use the HtmlInputRadioButton control to create a radio button on a Web page. The HtmlInputRadioButton control does not provide built-in functionality to display a caption for the radio button. To create a caption, use literal text in the Web page at the desired location. This allows you to determine where the caption is displayed relative to the radio button. For example, if you want to display the caption on the right side of the radio button, declare an HtmlInputRadioButton control, followed by the caption text, as shown in the following code.
<input type="radio"
id="Radio1"
name="Mode"
runat="server"/>
Caption Text<br>
You can optionally associate a quantity with the HtmlInputRadioButton control by setting the Value property. This is useful when you have multiple radio buttons and need to perform a calculation, based on the selection.
HtmlInputRadioButton controls can be grouped together by specifying a common value for the Name property of each radio button you want to include in the group.
Note: |
|---|
When you group HtmlInputRadioButton controls together, only one radio button in the group can be selected at a time. |
To determine whether the HtmlInputRadioButton control is selected, test the Checked property. If you have a group of HtmlInputRadioButton controls, you must iterate through the controls and test the Checked property of each control individually.
The HtmlInputRadioButton control provides a ServerChange event that is raised when the Checked property changes values between posts to the server. This allows you to create a custom event handler that performs a specific set of instructions when the event is raised, such as data validation.
For a list of initial property values for an instance of HtmlInputRadioButton, see the HtmlInputRadioButton constructor.
The following code example demonstrates how to use the HtmlInputRadioButton control to create a group of radio buttons.
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HtmlInputRadioButton Sample</title>
<script language="VB" runat="server">
Sub Button1_Click(sender As Object, e As EventArgs)
If Radio1.Checked = True Then
Span1.InnerHtml = "Option 1 is selected"
Else
If Radio2.Checked = True Then
Span1.InnerHtml = "Option 2 is selected"
Else
If Radio3.Checked = True Then
Span1.InnerHtml = "Option 3 is selected"
End If
End If
End If
End Sub 'Button1_Click
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlInputRadioButton Sample</h3>
<input type="radio"
id="Radio1"
name="Mode"
runat="server"/>
Option 1<br />
<input type="radio"
id="Radio2"
name="Mode"
runat="server"/>
Option 2<br />
<input type="radio"
id="Radio3"
name="Mode"
runat="server"/>
Option 3
<br />
<span id="Span1" runat="server" />
<br />
<input type="button"
id="Button1"
value="Enter"
onserverclick="Button1_Click"
runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HtmlInputRadioButton Sample</title>
<script language="C#" runat="server">
void Button1_Click(object sender, EventArgs e)
{
if (Radio1.Checked == true)
Span1.InnerHtml = "Option 1 is selected";
else if (Radio2.Checked == true)
Span1.InnerHtml = "Option 2 is selected";
else if (Radio3.Checked == true)
Span1.InnerHtml = "Option 3 is selected";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlInputRadioButton Sample</h3>
<input type="radio"
id="Radio1"
name="Mode"
runat="server"/>
Option 1<br />
<input type="radio"
id="Radio2"
name="Mode"
runat="server"/>
Option 2<br />
<input type="radio"
id="Radio3"
name="Mode"
runat="server"/>
Option 3
<br />
<span id="Span1" runat="server" />
<br />
<input type="button"
id="Button1"
value="Enter"
onserverclick="Button1_Click"
runat="server" />
</form>
</body>
</html>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>HtmlInputRadioButton Sample</title>
<script language="JSCRIPT" runat="server">
function Button1_Click(sender : Object, e : EventArgs){
if(Radio1.Checked)
Span1.InnerHtml = "Option 1 is selected"
else if(Radio2.Checked)
Span1.InnerHtml = "Option 2 is selected"
else if(Radio3.Checked)
Span1.InnerHtml = "Option 3 is selected"
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlInputRadioButton Sample</h3>
<input type="radio"
id="Radio1"
name="Mode"
runat="server"/>
Option 1<br />
<input type="radio"
id="Radio2"
name="Mode"
runat="server"/>
Option 2<br />
<input type="radio"
id="Radio3"
name="Mode"
runat="server"/>
Option 3
<br />
<span id="Span1" runat="server" />
<br />
<input type="button"
id="Button1"
value="Enter"
onserverclick="Button1_Click"
runat="server" />
</form>
</body>
</html>
System..::.Object
System.Web.UI..::.Control
System.Web.UI.HtmlControls..::.HtmlControl
System.Web.UI.HtmlControls..::.HtmlInputControl
System.Web.UI.HtmlControls..::.HtmlInputRadioButton
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference
Other Resources