Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all... I have a question about page life cycles... at least that's where I think the problem lies.

I have written some code to dynamically create paging buttons using a PagedDataSource. It all works as intended apart from one small problem :-(

There is a label showing the current page and total pages.. but it only gets updated to the correct current page when I click for a second time. Any help would be MUCH appreciated... (I'm trying to steer clear of J Query as I really don't have much experience with it.

This is the Draw buttons method.

C#
private void DrawButtons()
   {
       Button pagerButtonFirst = new Button();
       Button pagerButtonLast = new Button();

       pagerButtonFirst.Text = "first";
       pagerButtonFirst.Click += btnFirst_Click;
       pagerButtonFirst.CssClass = "PageEnds";

       pnlButtonFirst.Controls.Add(pagerButtonFirst);

       var paging = (Paging)Session[Globals.SessionsNames.SessTestimonials];

       for (int i = 0; i < paging.PagedSource.PageCount; i++)
       {
           var newButton = new Button();

           newButton.Text = (i + 1).ToString();
           newButton.Command += btnSpecfic_Click;
           newButton.CommandArgument = (i + 1).ToString();
           newButton.CssClass = "PageNumber";
           pnlButtonPages.Controls.Add(newButton);
       }

       pagerButtonLast.Text = "last";
       pagerButtonLast.Click += btnLast_Click;

       pagerButtonLast.CssClass = "PageEnds";
       pnlButtonLast.Controls.Add(pagerButtonLast);

       lblPageInfo.Text = string.Format("Showing page {0} of {1}. (total items {2})",
                                        paging.PagedSource.CurrentPageIndex + 1, paging.PagedSource.PageCount,
                                        paging.TotalItems.ToString());
   }
Posted
Comments
Sergey Alexandrovich Kryukov 15-May-13 15:58pm    
Something is not clear. "but it only gets updated to the correct current page when I click for a second time"... click what, exactly? What's the script of what you click on? When do you click at first time?
In other words, explain the scenario in detail, steps to reproduce the problem and all relevant code. Perhaps, create a code sample reduced to as simple as possible.
—SA
alexellice 15-May-13 16:13pm    
Sorry for not explaining better..

On the web page..

[First Page] [1] [2] [3] [Last Page] showing page 1 of 3

if I click page 2 it shows
[First Page] [1] [2] [3] [Last Page] showing page 1 of 3

if I click again
[First Page] [1] [2] [3] [Last Page] showing page 2 of 3

It's as if it only gets updated on the 2nd postback

(I should also mention that it does go to page 2 on the fist click... its just the text is not updated on the first click)
Sergey Alexandrovich Kryukov 15-May-13 17:11pm    
What a second. If "just the text is not update", how it can be the second page?
What is the current page when you first load the page? The problem is possibly there. Also, do you show current page by the style of 1, 2, 3... anchors?
—SA

1 solution

Please see my question. In the meanwhile, study this: http://msdn.microsoft.com/en-us/library/ms178472.aspx[^].

You will find all answers if you start from this point.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900