※只能適用於GirdView的換頁,如果是轉跳到不同url的頁面,則[上一頁]的history功能一樣失效。
實驗的結果,轉跳不同url也可成功"回上一頁"。
但如果GridView有做ajax篩選,則一樣會失敗。
目前解決辦法是,不要做ajax篩選,只有ajax換頁。
aspx File
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="true"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:SqlDataSource ID="SqlDataSource1" runat="server" > </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1"> </asp:GridView> </ContentTemplate> </asp:UpdatePanel>
vb File
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged '換頁時把頁碼加入歷史紀錄 If ScriptManager1.IsInAsyncPostBack And Not ScriptManager1.IsNavigating Then Dim index As Integer = GridView1.PageIndex ScriptManager1.AddHistoryPoint("PageIndex", index, "第 " & index + 1 & " 頁") End If End Sub Protected Sub ScriptManager1_Navigate(ByVal sender As Object, ByVal e As System.Web.UI.HistoryEventArgs) Handles ScriptManager1.Navigate '按上一頁會進到歷史紀錄的功能 Dim indexString As String = e.State("PageIndex") Page.Title = "第 " & indexString & " 頁" GridView1.PageIndex = CType(indexString, Integer) GridView1.DataSourceID = SqlDataSource1.ID End Sub
文章標籤
全站熱搜
留言列表