S
Shadow Lynx
In standard HTML, the <INPUT type="radio" name="x" /> control only
allows one radio button to be checked at a time. When more than one
are set as checked="true" then only the last one rendered appears as
checked. I would assume that asp:RadioButton objects that share the
same GroupName would not allow more than one Radio Button to be checked
(similar to the Radio Button List) but it seems to not be the case. If
I set one Radio Button's Checked property to True and then another one,
they both render HTML as Checked. Is this a bug or are
asp:RadioButtons supposed to work like this? At this point, the
workaround is to require setting of all RadioButtons' Checked property
to False in case any were previously True before setting the desired
RadioButton's Checked property to True.
Example:
<%@ Page Language="VB" AutoEventWireup="false" %>
<!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" >
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.RadioButton2.Checked = True
Me.RadioButton1.Checked = True ' You'd think this would uncheck
RadioButton2
End Sub
</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server"
GroupName="TestGroup" Text="Radio Button 1" />
<asp:RadioButton ID="RadioButton2" runat="server"
GroupName="TestGroup" Text="Radio Button 2" /></div>
</form>
</body>
</html>
allows one radio button to be checked at a time. When more than one
are set as checked="true" then only the last one rendered appears as
checked. I would assume that asp:RadioButton objects that share the
same GroupName would not allow more than one Radio Button to be checked
(similar to the Radio Button List) but it seems to not be the case. If
I set one Radio Button's Checked property to True and then another one,
they both render HTML as Checked. Is this a bug or are
asp:RadioButtons supposed to work like this? At this point, the
workaround is to require setting of all RadioButtons' Checked property
to False in case any were previously True before setting the desired
RadioButton's Checked property to True.
Example:
<%@ Page Language="VB" AutoEventWireup="false" %>
<!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" >
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.RadioButton2.Checked = True
Me.RadioButton1.Checked = True ' You'd think this would uncheck
RadioButton2
End Sub
</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server"
GroupName="TestGroup" Text="Radio Button 1" />
<asp:RadioButton ID="RadioButton2" runat="server"
GroupName="TestGroup" Text="Radio Button 2" /></div>
</form>
</body>
</html>