1
votes

I have 2 RadioButtonLists and I want only one option to be selected, f.i. if you select an option in List 1 the selection in List 2 should be cleared.

AutoPostBack and EnableViewState is set to true, but still the Method never fires. I have also checked if the Index actually changes, it does. I think that the PostBack just doesn't occur, but I don'T know why.

I'm thankful for any help.

ascx:

<asp:RadioButtonList ID="_listOne" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButtonList>
<asp:RadioButtonList ID="_listTwo" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButtonList>

Code Behind:

protected void ListOneIndexChanged(object sender, EventArgs e)
{
    _listTwo.ClearSelection();
}
protected void ListTwoIndexChanged(object sender, EventArgs e)
{
    _listOne.ClearSelection();
}
2
"I think that the PostBack just doesn't occur" - Have you verified this? The browser's debugging tools will tell you if a request is made, what the response is, if there are any client-side errors, etc. Does anything happen in the Page_Load event during the post-back which stops this? Maybe the lists are re-populated in that method and the selection changed event is lost? You need to debug this a little.David
Are you using updatepanels at all?wingyip
Yes, I have verified that there is no request. Nothing happens in the Page_Load and the lists are also not repopulated. When I submit the page the right Index is submitted, so I think the index actually changes?user3198448
@wingyip No I am not using updatepanelsuser3198448

2 Answers

1
votes

change the control to RadioButton and add GroupName to them will do the trick:

<asp:RadioButton ID="_listOne" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButton>
<asp:RadioButton ID="_listTwo" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButton>
0
votes

try to use just one radibuttonlist and options.

 <asp:RadioButtonList id="radiolist1" runat="server" OnSelectedIndexChanged="ListOneIndexChanged">

   <asp:ListItem selected="true">Item 1</asp:ListItem>
   <asp:ListItem>Item 2</asp:ListItem>
   <asp:ListItem>Item 3</asp:ListItem>
   <asp:ListItem>Item 4</asp:ListItem>
</asp:RadioButtonList>