<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="true" EnableSecureHistoryState="false" onnavigate="ScriptManager1_Navigate">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:LinkButton ID="LinkButton1" runat="server"
onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server"
onclick="LinkButton2_Click">LinkButton</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server"
onclick="LinkButton3_Click">LinkButton</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server"
onclick="LinkButton4_Click">LinkButton</asp:LinkButton>
<br />
<asp:Label ID="Label1" runat="server" ></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Code behind Part
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Label1.Text = "first";
ScriptManager1.AddHistoryPoint("value", Label1.Text); // Adding history points
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Label1.Text = "second";
ScriptManager1.AddHistoryPoint("value", Label1.Text);
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Label1.Text = "third";
ScriptManager1.AddHistoryPoint("value", Label1.Text);
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Label1.Text = "fourth";
ScriptManager1.AddHistoryPoint("value", Label1.Text);
}
protected void ScriptManager1_Navigate(object sender, HistoryEventArgs e) // Event handler for restoring state
{
Label1.Text = e.State["value"];
}
First try to run this code by setting script manager EnableHistory="false" and Commenting all the Lines where a history point is added and also the ScriptManager1_Navigate Method and observe the browsers back button is disabled and then set EnableHistory="true" and uncomment all the commented lines and observe the back button is functioning properly. Observe the change in url, it contain a long value followed by a "#" if EnableSecureHistoryState is set to true actually this is the hash value of the state encoded due to security reason if EnableSecureHistoryState is set to false then you will observe the actual value of the state.
NB: if script manager is included in master page then add a scriptmanagerproxy to your page for adding history points do something like this
ScriptManager.GetCurrent(this.Page).AddHistoryPoint("value", YourValue);
add the event handler part in ScriptManagerProxy Navigate Event.