Hi,
I see a few options:
1) use a cookie (works better for me, could also be done with session of course) to store the value and build every link you have in the page to include something like "postedback=true" in the querystring, look for that on page load and if it is not there reset the cookie.
2) if it is only the pagination that causes this change your pagination to use postbacks. I built a simple custom pagination control (did this because the normal pagination would not use postbacks but navigateurl leading to this exact problem). It looks a bit like this (is more complicated here because this source resides in a controll that is loaded in runtime through loadcontrol):
ascx file:
<asp:Repeater id="lstContentProduct" runat="server" Visible="true">
etc....
</asp:Repeater>
<asp:PlaceHolder ID="pagingControl" runat="server" Visible="false" >
<asp:HiddenField ID="HiddenCurrentPage" runat="server" />
<table width="100%">
<tr>
<td width="50%" align="left" valign="top">
<asp:PlaceHolder ID="plhPageOf" runat="server" />
</td>
<td width="50%" align="right" valign="top">
<asp:PlaceHolder ID="plhPageNums" runat="server" />
</td>
</tr>
</table>
</asp:PlaceHolder>
Code behind:
.....
protected int CurrentPage = 1;
protected int TotalPages = -1;
protected int PageSize = 10;
private int _CurrentPage = -1;
.....
protected void pagingClicked(Object sender, CommandEventArgs e)
{
CartasticProductController CPC = new CartasticProductController();
switch (e.CommandName)
{
case "dopaging":
_CurrentPage = Convert.ToInt32(e.CommandArgument.ToString());
HiddenCurrentPage.Value = e.CommandArgument.ToString();
updateRepeater();
break;
}
}
.....
private void updateRepeater()
{
YourController CPC = new YourController(); // use your own controller here
List<YourInfo> CPI = CPC.GetSometyhing(); // and hre your own info class
PagedDataSource lstContent = new PagedDataSource();
lstContent.DataSource = CPI;
if (_CurrentPage > 0)
{
CurrentPage = _CurrentPage;
}
if (lstContent.PageSize > 0)
{
lstContent.PageSize = PageSize;
lstContent.CurrentPageIndex = CurrentPage - 1;
lstContent.AllowPaging = true;
}
lstContentProduct.DataSource = lstContent;
lstContentProduct.DataBind();
if (PageSize == 0 || CPI.Count <= PageSize)
{
pagingControl.Visible = false;
}
else
{
pagingControl.Visible = true;
plhPageNums.Controls.Clear();
plhPageOf.Controls.Clear();
TotalPages = CPI.Count/PageSize;
Label lblPageOf = new Label();
lblPageOf.ID = "lblPageOf";
lblPageOf.CssClass = "Normal";
lblPageOf.Text = Localization.GetString("pagePage.Text", this.LocalResourceFile);
lblPageOf.Text += " " + CurrentPage + " ";
lblPageOf.Text += Localization.GetString("pageOf.Text", this.LocalResourceFile);
lblPageOf.Text += " " + TotalPages + " ";
plhPageOf.Controls.Add(lblPageOf);
int PageNr = 1;
if (CurrentPage>1 && TotalPages>1)
{
LinkButton hlNumLink = new LinkButton();
hlNumLink.ID = "Paging_Prev";
hlNumLink.CssClass = "Normal";
hlNumLink.Text = Localization.GetString("pagePrev.Text", this.LocalResourceFile)+" ";
hlNumLink.CommandName = "dopaging";
hlNumLink.CommandArgument = Convert.ToString(CurrentPage - 1); ;
hlNumLink.Command += new CommandEventHandler(pagingClicked);
plhPageNums.Controls.Add(hlNumLink);
}
while (PageNr <= TotalPages)
{
if (!(PageNr == CurrentPage))
{
LinkButton hlNumLink = new LinkButton();
hlNumLink.ID = "Paging_" + PageNr.ToString();
hlNumLink.CssClass = "Normal";
hlNumLink.Text = PageNr.ToString() + " ";
hlNumLink.CommandName = "dopaging";
hlNumLink.CommandArgument = PageNr.ToString();
hlNumLink.Command += new CommandEventHandler(pagingClicked);
plhPageNums.Controls.Add(hlNumLink);
}
else
{
Label hlNumLink = new Label();
hlNumLink.ID = "Paging_" + PageNr.ToString();
hlNumLink.CssClass = "Normal";
hlNumLink.Text = PageNr.ToString() + " ";
plhPageNums.Controls.Add(hlNumLink);
}
PageNr = PageNr + 1;
}
if (CurrentPage < TotalPages)
{
LinkButton hlNumLink = new LinkButton();
hlNumLink.ID = "Paging_Next";
hlNumLink.CssClass = "Normal";
hlNumLink.Text = Localization.GetString("pageNext.Text", this.LocalResourceFile);
hlNumLink.CommandName = "dopaging";
hlNumLink.CommandArgument = Convert.ToString(CurrentPage + 1);
hlNumLink.Command += new CommandEventHandler(pagingClicked);
plhPageNums.Controls.Add(hlNumLink);
}
}
HTH
Alexander