I have an ASP.NET page with two radio buttons. Buttons use auto-reverse to perform server-side logic. If you select the second button, the page will return and correctly display a message that the second button is selected. If you click the back button of the browser, the state of button 2 will be checked until the message returns to the statement that the specified button is checked. This leads to a situation that is clearly undesirable since the state of the switches and messages is now out of sync. I know this is a caching problem, but it seems strange to me that the browser remembers the previous state of the label, but not the previous state of the switch.
What is the best way to handle this situation? In this situation, it is undesirable to disable the cache or use the "Back" button.
The following code example demonstrates this behavior:
[The 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 for:]
protected void rb_CheckedChanged(object sender, EventArgs e)
{
if (rb1.Checked == true)
lbl1.Text = "Button 1";
else
lbl1.Text = "Button 2";
}
source
share