Hi!
I have a 'shop' page, where all the items in the shop is listed. I have a sortingfunction, to decide how many results pr. page I want to see.
I also have a pager. The pager is built with two buttons (a Previous- and Next-pagebutton), and a textbox which shows the pagenumber. The pager is on both the top, and bottom of the page.
When I change the text in the textbox, the following code fires:
protected void tbPageNumberTop_TextChanged(object sender, EventArgs e)
{
tbPageNumberBottom.Text = tbPageNumberTop.Text;
updpanMain.Update();
}
This causes a pageload, where I get the number from the textbox, and parse it to an integer, which I can use to dynamically create an SQL request. This works just perfectly.
Here's my problem. When I click the "Next" button or "Previous" button, the text in the textbox changes, but when I get the number from the textbox, I get the value of the textbox as it was BEFORE the button was clicked. How do I obtain the correct pagenumber?
Here's my Click-code:
protected void btnNextPage_Click(object sender, EventArgs e)
{
int PageNumber = Convert.ToInt32(tbPageNumberTop.Text);
PageNumber += 1;
tbPageNumberTop.Text = PageNumber.ToString();
tbPageNumberBottom.Text = PageNumber.ToString();
updpanMain.Update();
}
protected void btnPrevPage_Click(object sender, EventArgs e)
{
int PageNumber = Convert.ToInt32(tbPageNumberTop.Text);
PageNumber -= 1;
tbPageNumberTop.Text = PageNumber.ToString();
tbPageNumberBottom.Text = PageNumber.ToString();
updpanMain.Update();
}
And here's what happens on page_load
if (!this.IsPostBack)
{
intStartPosition = 0;
intPageNumber = 1;
tbPageNumberBottom.Text = intPageNumber.ToString();
tbPageNumberTop.Text = intPageNumber.ToString();
}
if (tbPageNumberTop.Text != "1" || tbPageNumberBottom.Text != "1")
{
intPageNumber = Convert.ToInt32(tbPageNumberTop.Text);
}
else
{
intPageNumber = 1;
}
intStartPosition = (intPageNumber * intItemsPrPage) - intItemsPrPage;
strResultsPrPage = intItemsPrPage.ToString();
intStartPosition represents the first LIMIT integer in my SQL string, and strResultsPrPage represents the second integer, i.e. LIMIT 100, 500 is showing results from 500 to 600. (Page 5, with 100 results per page)