Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater Server Control


View products that this article applies to.

This article was previously published under Q316495

↑ Back to the top


Symptoms

When you add a ASP.NET RadioButton control to the ItemTemplate of a data-bound Repeater server control, the RadioButton control that you created is not mutually exclusive when you run the ASP.NET page. This problem occurs even if the GroupName attribute is set for the RadioButton controls.

↑ Back to the top


Cause

This problem occurs because the Repeater server control implements the INamingContainer interface, which requires that all controls that are nested within it must have a unique name when rendered in Hypertext Markup Language (HTML). Therefore, the HTML name attribute of any rendered child server control is unique.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

HTML versions 3.2 and later require that all radio button controls that are mutually exclusive have the same unique name attribute. Because controls that are inside a bound Repeater sever control must have a unique name, the rendered HTML RadioButton control is not mutually exclusive.

Note that the GroupName attribute should resolve this problem. If you set the GroupName attribute, every RadioButton control should render the same HTML name attribute that was specified by the GroupName attribute of the server control. The expected behavior does not occur because the unique client naming overrides the use of the GroupName property.

Steps to Reproduce the Problem

  1. Create a new Microsoft Visual C# .NET Web application project.
  2. In the Design view, drag a Repeater server control to the default Webform1.aspx page.
  3. In HTML view, add the following <itemtemplate> code to Repeater1:
    <ItemTemplate>
    <asp:RadioButton id="RadioButton1" runat="server" GroupName="RadioButton1" Text="<%#Container.DataItem.ToString()%>">
    </asp:RadioButton><br>
    </ItemTemplate>
    					
  4. In the Page_Load event of Webform1.aspx, add the following code:
    			TestArray[0]="Test Value 0";
    			TestArray[1]="Test Value 1";
    			TestArray[2]="Test Value 2";
    
    			Repeater1.DataSource = TestArray;
    			Repeater1.DataBind();
    					
  5. Add the following instance variable to the Page class:
    protected String[] TestArray = new String[3];
    					
  6. Build the project, and then view the page in the browser.
  7. Click each individual RadioButton control to verify that you can select them without changing the value of the other RadioButton controls.

↑ Back to the top


Keywords: KB316495, kbwebforms, kbservercontrols, kbnofix, kbdatabinding, kbbug

↑ Back to the top

Article Info
Article ID : 316495
Revision : 6
Created on : 2/23/2007
Published on : 2/23/2007
Exists online : False
Views : 385