views:

132

answers:

2

I have a number of own UserControls on a page. Each has the same type and a radio button inside. How can I force only one RadioButton to be checked?

I did next:

class myControl : UserControl
{
  [Category("Settings")]
  public string GroupName
  {
     set
     {
       radio.GroupName = value;
     }
   }
}

but it doesn't helped.

Or only one way is to (un)check each radio button manually?

+1  A: 

Hmmm, You may want to use the radiobuttonlist control instead. See: http://www.codetoad.com/asp.net/aspnetcontrols11.asp.

radiobuttonlist controls give you the grouping that you are after.

Lanceomagnifico
I cannot use RadioButtonList because besides RadioButtons my UserControls contains a lot of other controls, but I need common GroupName for all my UserControls on the page
abatishchev
Sorry I don't have the code to hand, but in the past when I've been in a situation like yours, you can just use normal html radiobutton <input> controls, but make them runat="server" so that you can access them from the codebehind. Then you can group them as per normal, and they will only let one be selected at a time.Or you can do some javascript to check clientside to make sure only one is checked. I usually use JQuery for this sort of thing, it's pretty powerful.
Lanceomagnifico
+1  A: 

Use input type="radio" with this and give all the radio buttons the same name but different id. This way it will work without any problem. Try it yourself and let me know.

lakhlaniprashant.blogspot.com