ASP.NET bug with RadioButton GroupName in Repeater

John Avis by | September 1, 2019 | ASP.NET Web Forms Web Development

I rediscovered a bug in ASP.NET that affects RadioButtons inside repeaters. Here is my solution to the problem.
I was recently working on an ASP.NET Web Forms project where I needed to create a group of RadioButtons with a Repeater.

I rediscovered a bug in ASP.NET that results in each RadioButton having a unique GroupName which means they all operate independently.

Of course I attempted to take the easy route of Google-ing the problem and I found many discussions and posts about this issue. I looked at and tried some of the suggested workarounds but didn't like some and others didn't work.

Inspired by some JavaScript solutions that simply deselect all other RadioButtons in the same group, I put together the following simple jQuery script to do the same.

var clientId=$(this).attr('id');
if($(this).attr('id') != clientId){

You need to replace "RadioButton1" with the ID of your RadioButton control in the two places in the script.

I added this script in the code-behind file in the Page_PreRender event when it was needed, like this:

Page.ClientScript.RegisterStartupScript(this.GetType(), "RadioButton1", "$(function(){$('[name$="$RadioButton1"]').click(function(){var clientId=$(this).attr('id');$('[name$="$RadioButton1"]').each(function(){if($(this).attr('id')!=clientId){$(this).prop('checked',false);}});});});", true);

I know this script could be improved a lot, but as is often the case, as soon as my prototype worked as required I left it as is and moved on to other priorities. No time for optimisation.


[A Google search shows many people have faced this problem... Wonder why it hasn't been fixed?]

Related Posts

Intermittent "Unable to read data from the transport connection: net_io_connectionclosed" errors

by John Avis | May 6, 2020

If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.

500 Internal Server Error after migrating from IIS 7.5 to IIS 10

by John Avis | November 4, 2019

As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.

tagInput: A simple jQuery plugin for tag entry using Bootstrap 4

by John Avis | October 15, 2019

For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.


There are no comments yet. Be the first to leave a comment!

Leave a Comment



...random postings about web development and programming, Internet, computers and electronics topics.

I recommend ASPnix for web hosting and Crazy Domains for domain registration.


Get the latest posts delivered to your inbox.