RadioButton 类
表示单选按钮控件。
**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)
语法
声明
Public Class RadioButton
Inherits CheckBox
Implements IPostBackDataHandler
用法
Dim instance As RadioButton
public class RadioButton : CheckBox, IPostBackDataHandler
public ref class RadioButton : public CheckBox, IPostBackDataHandler
public class RadioButton extends CheckBox implements IPostBackDataHandler
public class RadioButton extends CheckBox implements IPostBackDataHandler
备注
RadioButton 服务器控件允许您用页的其他内容点缀组中的单选按钮。如果这些按钮全都共享同一个 GroupName 属性,则在逻辑上属于一个组。
提示
可以使用 RadioButton 控件显示用户输入,而用户输入可能包含恶意的客户端脚本。在应用程序中显示从客户端发送来的任何信息之前,请检查它们是否包含可执行脚本、SQL 语句或其他代码。ASP.NET 提供输入请求验证功能以阻止用户输入中的脚本和 HTML。还提供验证服务器控件以判断用户输入。有关更多信息,请参见 验证服务器控件语法。
辅助功能
默认情况下为此控件呈现的标记可能不符合 Web 内容辅助功能准则 1.0 (WCAG) 中优先级为 1 的准则等辅助功能标准。有关此控件的辅助功能支持的详细信息,请参见 ASP.NET 控件和辅助功能。
示例
下面的代码示例阐释如何使用 RadioButton 控件。
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script language="VB" runat="server">
Sub SubmitBtn_Click(Sender As Object, e As EventArgs)
If Radio1.Checked Then
Label1.Text = "You selected " & Radio1.Text
ElseIf Radio2.Checked Then
Label1.Text = "You selected " & Radio2.Text
ElseIf Radio3.Checked Then
Label1.Text = "You selected " & Radio3.Text
End If
End Sub
</script>
</head>
<body>
<h3>RadioButton Example</h3>
<form runat=server>
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id=Radio1 Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br>
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><p>
<asp:RadioButton id=Radio2 Text="Compact" GroupName="RadioGroup1" runat="server"/><br>
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><p>
<asp:RadioButton id=Radio3 runat="server" Text="Full" GroupName="RadioGroup1" /><br>
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><p>
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat=server/>
<asp:Label id=Label1 font-bold="true" runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void SubmitBtn_Click(Object Sender, EventArgs e) {
if (Radio1.Checked) {
Label1.Text = "You selected " + Radio1.Text;
}
else if (Radio2.Checked) {
Label1.Text = "You selected " + Radio2.Text;
}
else if (Radio3.Checked) {
Label1.Text = "You selected " + Radio3.Text;
}
}
</script>
</head>
<body>
<h3>RadioButton Example</h3>
<form runat=server>
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id=Radio1 Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br>
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><p>
<asp:RadioButton id=Radio2 Text="Compact" GroupName="RadioGroup1" runat="server"/><br>
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><p>
<asp:RadioButton id=Radio3 runat="server" Text="Full" GroupName="RadioGroup1" /><br>
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><p>
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat=server/>
<asp:Label id=Label1 font-bold="true" runat="server" />
</form>
</body>
</html>
继承层次结构
System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.CheckBox
System.Web.UI.WebControls.RadioButton
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
RadioButton 成员
System.Web.UI.WebControls 命名空间
CheckBox 类