Ajax +浏览器历史记录

时间:2013-01-20 20:03:49

标签: asp.net ajax

我正在关注管理浏览器历史记录asp.net示例文章,但是在单击浏览器后退按钮后更新 LabelHistoryData 标签时遇到问题。我在

处放了一个断点
LabelHistoryData.Text = Server.HtmlEncode(e.State["s"]);

但是以某种方式点击btnGetInboxList或btnGetSentboxList后面的浏览器后退按钮,LabelHistoryData.Text值始终为null。下面是我的代码的一部分。请有人建议。

感谢。

     <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);
            }

1 个答案:

答案 0 :(得分:0)

事实证明UpPanel UpdateMode必须设置为Always。

相关问题