I have an ASP.NET page with two radio buttons. The buttons use an auto-postback to run server side logic. If you select the second button, the page posts back and correctly displays a message that the second button is selected. If the browser back button is now clicked, the state of button 2 stays checked while the message reverts to saying that button one is checked. This results in a situation that is obviously undesirable because the state of the radio buttons and message are now out of sync. I know this is a caching issue but I find it odd that the browser remembers the previous state of the label but not the previous state of the radio button.
What is the best way to handle this situation? It's undesirable in this situation to disable cache or the use of the back button.
The following code example exhibits this behavior:
[Form:]
<asp:RadioButton ID="rb1" runat="server" AutoPostBack="true" Text="Button1" OnCheckedChanged="rb_CheckedChanged"
GroupName="rbgroup" Checked="true" />
<br />
<asp:RadioButton ID="rb2" runat="server" AutoPostBack="true" Text="Button2" OnCheckedChanged="rb_CheckedChanged"
GroupName="rbgroup" />
<br />
<hr />
<asp:Label ID="lbl1" runat="server">Button 1</asp:Label>
[Code Behind:]
protected void rb_CheckedChanged(object sender, EventArgs e)
{
if (rb1.Checked == true)
lbl1.Text = "Button 1";
else
lbl1.Text = "Button 2";
}