I am following the Managing Browser History asp.net example article but I have a problem with updating the LabelHistoryData label after clicking the browser back button. I placed a breakpoint at
LabelHistoryData.Text = Server.HtmlEncode(e.State["s"]);
but somehow after clicking btnGetInboxList or btnGetSentboxList follow by the browser back button, the LabelHistoryData.Text value is always null. Below is a portion of my code. Someone please kindly advice.
Thanks.
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" OnNavigate="OnNavigateHistory" EnableHistory="true" EnableSecureHistoryState="false" />
<asp:UpdatePanel ID="uiupInboxMainGrid" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="LabelHistoryData" />
<asp:Button ID="btnGetMessageContent" runat="server" Text="MsgContent" OnClick="GetMessageContent_Click" />
<asp:Button ID="btnGetInboxList" runat="server" Text="Inbox" OnClick="GetInboxList_Click"/>
<asp:Button ID="btnGetSentboxList" runat="server" Text="OutBox" OnClick="GetSentBoxList_Click" />
</ContentTemplate>
</asp:UpdatePanel>
public void OnNavigateHistory(object sender, HistoryEventArgs e)
{
LabelHistoryData.Text = Server.HtmlEncode(e.State["s"]);
}
protected void GetInboxList_Click(object sender, EventArgs e)
{
LabelHistoryData.Text = ((Button)sender).Text;
ScriptManager.GetCurrent(this).AddHistoryPoint("s", LabelHistoryData.Text, "Entry: " + LabelHistoryData.Text);
}
protected void GetSentBoxList_Click(object sender, EventArgs e)
{
LabelHistoryData.Text = ((Button)sender).Text;
ScriptManager.GetCurrent(this).AddHistoryPoint("s", LabelHistoryData.Text, "Entry: " + LabelHistoryData.Text);
}
protected void GetMessageContent_Click(object sender, EventArgs e)
{
LabelHistoryData.Text = ((Button)sender).Text;
ScriptManager.GetCurrent(this).AddHistoryPoint("s", LabelHistoryData.Text, "Entry: " + LabelHistoryData.Text);
}
Turns out that the UpPanel UpdateMode has to be set to Always.