views:

27

answers:

1

I have a RadioButtonList in an UpdatePanel.

Say I click the second button (value of "1"). It posts back, and hits my event handler --

  • I can watch the POST go out in Firebug, and it is clearly sending the correct form value of "1"
  • I can catch the event handler with a breakpoint, and check Request.Form and clearly see that the incoming value is a "1"

However, the SelectedValue of the control (StatusButtons.SelectedValue) is always "0" (actually, it's whatever it was when the page originally loaded -- this is usually "0").

Is there some other way I should be getting the value selected in the RadioButtonList?

<asp:UpdatePanel runat="server" UpdateMode="Always">
    <ContentTemplate>
         <asp:RadioButtonList OnSelectedIndexChanged="StatusButtons_OnSelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="true" ID="StatusButtons" runat="server">
            <asp:ListItem Value="0">Foo</asp:ListItem>
            <asp:ListItem Value="1">Bar</asp:ListItem>
            <asp:ListItem Value="2">Baz</asp:ListItem>
         </asp:RadioButtonList>       
    </ContentTemplate>
</asp:UpdatePanel>
A: 

Turns out I'm an idiot. I didn't acknowledge that the Ajax postback goes through an entire page lifecycle. I somehow had it in my head that it only ran the postback method it was calling.

Sure enough, in Page_Load, I was initializing the value of this control...so I was re-initializing it on every postback.

Silly.

Deane