0

I need help, I have a DataPager inside the update panel and and working well, but when I refresh page or going on back button form some other page DataPager reset always to the first page.

For example if I was on the tenth page and refresh page, data pager reset to first.

Is there any way to keep the current page on data pager?

My code is:

<asp:SqlDataSource ID="SqlDataSource1" EnableCaching="True" CacheDuration="4000" CacheExpirationPolicy="Sliding"
runat="server" ConnectionString="<%$ ConnectionStrings:blabla %>" SelectCommand=""></asp:SqlDataSource>

<asp:UpdatePanel ID="UpdatePanelnajgornji" runat="server" >
<ContentTemplate>
<asp:ListView ID="ListView1"  runat="server" ondatabound="ListView1_DataBound" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" Visible='<%# !(Eval("Slika") is DBNull) %>' runat="server" NavigateUrl='<%# Eval("Link") %>' title='<%# Eval("Naslov") %>'>
<asp:Image ID="Image1" runat="server" AlternateText='<%# Eval("Naslov") %>' ImageUrl='<%# Eval("Slika") %>' /></asp:HyperLink>
</ItemTemplate>
</asp:ListView>
<br />
    <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
        <Fields>
            <asp:NextPreviousPagerField />
        </Fields>
    </asp:DataPager>

</ContentTemplate>
</asp:UpdatePanel>
Milan
  • 17
  • 7

1 Answers1

0

Browser refresh creates new objects (and thus clears the state of the DataPager). You need to save the current page either in the Session or the ViewState, then initialize the control using those values if they exist in the codebehind. Store the values in an unload event listener.