RadioButton 웹 서버 컨트롤 선언 구문
업데이트: 2007년 11월
페이지에서 개별 라디오 단추를 만드는 데 사용하는 컨트롤입니다. 여러 개의 라디오 단추를 하나의 그룹으로 만들어 한 번에 한 항목만 선택하도록 할 수 있습니다.
<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"
/>
설명
RadioButton 서버 컨트롤을 사용하여 Web Forms 페이지에 라디오 단추를 만들 수 있습니다. 컨트롤에 표시할 텍스트를 지정하려면 Text 속성을 설정합니다. 텍스트를 라디오 단추의 왼쪽 또는 오른쪽에 표시할 수 있으므로 TextAlign 속성을 설정하여 텍스트 위치를 제어합니다. 각 RadioButton 컨트롤에 대해 동일한 GroupName을 지정하여 여러 라디오 단추를 그룹화할 수 있습니다. 이렇게 만든 그룹에서는 한 번에 한 항목만 선택할 수 있습니다.
참고
RadioButtonList 컨트롤을 사용할 수도 있습니다. RadioButtonList 컨트롤을 사용하면 데이터 바인딩을 사용하여 좀 더 쉽게 라디오 단추 집합을 만들 수 있고 개별 RadioButton 컨트롤을 사용하면 레이아웃을 세밀하게 제어할 수 있다는 이점이 있습니다.
RadioButton 컨트롤을 선택했는지 여부를 확인하려면 Checked 속성을 테스트합니다.
경고
텍스트는 RadioButton 컨트롤에 표시된 후에 HTML로 인코딩됩니다. 따라서 텍스트의 HTML 태그 내에 스크립트를 포함시킬 수 있습니다. 컨트롤 값을 사용자 입력에서 가져온 경우 값이 유효한지 확인하여 보안상의 허점을 방지합니다.
RadioButton 웹 서버 컨트롤의 속성과 이벤트에 대한 자세한 내용은 RadioButton 클래스 설명서를 참조하십시오.
예제
아래 예제에서는 RadioButton 컨트롤을 사용하여 한 번에 하나의 옵션만 선택할 수 있는 옵션 집합을 사용자에게 표시하는 방법을 보여 줍니다.
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>RadioButton Example</title>
<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 id="form1" 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><br />
<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><br />
<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><br />
<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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>RadioButton Example</title>
<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 id="form1" 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><br />
<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><br />
<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><br />
<asp:button text="Submit" OnClick="SubmitBtn_Click" runat="server"/>
<asp:Label id="Label1" font-bold="true" runat="server" />
</form>
</body>
</html>