0

There is a bug with the ASP .NET Web Forms RadioButtonList - if you uncheck all the radios on the client-side (with javascript), after you do a postback the first item in the list will be selected.

For example, try running the following jquery:

$('#myRadioList input').attr('checked', '');

After you do a postback, the first item in the RadioButtonList will be selected.

Anyone know an elegant work around?

cbp
  • 25,252
  • 29
  • 125
  • 205

1 Answers1

0

It's because by design you will need to choose one option

To uncheck all:

 $('input[type=radio]').prop('checked', false);

place it to the end of the page or inside

a $(function() {}); or $(document).ready(function() {}); block

P.S. Use prop instead of attr if jQuery 1.6+

.prop() vs .attr()

Community
  • 1
  • 1
balexandre
  • 73,608
  • 45
  • 233
  • 342
  • I know how to do it using JQuery (I showed how to do it in my questions even) - the problem is that it doesn't persist when you post back! – cbp May 25 '11 at 09:55
  • are you populating your lists only inside `if(!Page.IsPostBack)` event, or every time you load that page? – balexandre May 25 '11 at 10:38
  • The list is populated declaratively (i.e. in the aspx, not the codebehind). – cbp May 26 '11 at 01:42