Checking individual Radio Buttons with the same GroupName doesn't work

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top