Like I wrote in the title, the code-behind gets the wrong value when I try to change the selection of a RadioButton.
Dilemma.aspx:
<asp:RadioButtonList ID="rbList" runat="server">
<asp:ListItem Text="Yes, please." />
<asp:ListItem Text="No, thanks." />
<asp:ListItem Text="Ummm... maybe." />
</asp:RadioButtonList>
<asp:Button ID=""btnChoose" runat="server" text="OK" OnClick="btnChoose_Click" />
Dilemma.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
int initialIndex = GetInitialIndex(); // Simplified for sake of question.
rbList.SelectedIndex = initialIndex; // This works.
}
protected void btnChoose_Click(object sender, EventArgs e)
{
int selection = rbList.SelectedIndex; // This gets it wrong!
}
Instead of getting the newly-selected RadioButton, the code-behind still believes that the selected index is the initial index.
Why?
Somebody posted this answer, but deleted it for some reason.
Whoever it is who posted this answer before me – it works!