The issue i am facing is when the page number is clicked it forces a full page refresh. I have attempted a couple of changes on the UpdatePanel i.e. adding Conditional update but nothing stops the page from a full reload.
Any pointers? Or have i missed some basic configuration somewhere?
protected int CurrentPage
{
get
{
// look for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default to showing the first page
else
return (int)o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
protected int PageCount
{
get
{
// look for current page count in ViewState
object o = this.ViewState["_PageCount"];
if (o == null)
return 1; // default to just 1 page
else
return (int)o;
}
set
{
this.ViewState["_PageCount"] = value;
}
}
private static DataSet getData() {
DataSet ds = new DataSet();
string conStr = ConfigurationManager.ConnectionStrings["conStr"].ToString();
using (SqlConnection conn = new SqlConnection(conStr)) {
string query = "select * from simpletb";
using (SqlCommand cmd = new SqlCommand(query, conn)) {
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
}
}
return ds;
}
protected void GetItems()
{
PagedDataSource pagedData = new PagedDataSource();
pagedData.AllowPaging = true;
pagedData.PageSize = 10;
pagedData.DataSource = getData().Tables[0].DefaultView;
pagedData.CurrentPageIndex = CurrentPage;
PageCount = pagedData.PageCount;
// Wire up the page numbers
if (pagedData.PageCount > 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pagedData.PageCount; i++)
if (i == CurrentPage)
{
pages.Add("<b>" + (i + 1).ToString() + "</b>");
}
else
{
pages.Add((i + 1).ToString());
}
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
{
rptPages.Visible = false;
}
Repeater1.DataSource = pagedData;
Repeater1.DataBind();
}
protected void rptPages_ItemCommand(object source,RepeaterCommandEventArgs e)
{
CurrentPage = Convert.ToInt32(e.CommandArgument) - 1;
GetItems();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rptPages.ItemCommand += new RepeaterCommandEventHandler(rptPages_ItemCommand);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GetItems();
}
I set up a text input box to test, and result:
Hope this can help you.
Best regards,
Xudong Peng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
26 Points
81 Posts
Repeater causes whole page to reload inside update panel
Jul 23, 2020 02:24 PM|JamieP1|LINK
Hi all
Below is my code which uses GetData to load a repeater with data and the second repeater (rptPaging) is used for pagination.
Code behind
The issue i am facing is when the page number is clicked it forces a full page refresh. I have attempted a couple of changes on the UpdatePanel i.e. adding Conditional update but nothing stops the page from a full reload.
Any pointers? Or have i missed some basic configuration somewhere?
Thanks
Contributor
2090 Points
668 Posts
Re: Repeater causes whole page to reload inside update panel
Jul 24, 2020 07:09 AM|XuDong Peng|LINK
Hi JamieP1,
Based on your description, I created a simple example to reproduce your problem.
I modified part of the code, and now it can switch page numbers normally without refreshing the entire page.
Please refer to code below:
I set up a text input box to test, and result:
Hope this can help you.
Best regards,
Xudong Peng
Contributor
2090 Points
668 Posts
Re: Repeater causes whole page to reload inside update panel
Aug 06, 2020 08:30 AM|XuDong Peng|LINK
Hi jamieP1,
Have your problem solved?