Set StartIndex

3 posts, 0 answers
  1. Jens-Thomas
    Jens-Thomas avatar
    2 posts
    Member since:
    Sep 2010

    Posted 14 Aug 2014 Link to this post

    Hi,

    I'm calling a page containing a data pager. Part of my initial call url is a page number I would like to go to.
    I searched around and tried a lot of things without success:
    - FireCommand
    - SEO Paging

    What is the designed way to specify a start page for a data pager?

    THANKS!
  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 19 Aug 2014 Link to this post

    Hi Jens,

    I have already provided an answer in the official support ticket you have opened regarding this matter. In order to avoid duplicate posts I would kindly like to ask you to post your queries there. Later you can share your findings here so other community members can benefit from them.

    Regards,
    Angel Petrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jens-Thomas
    Jens-Thomas avatar
    2 posts
    Member since:
    Sep 2010

    Posted 25 Aug 2014 in reply to Angel Petrov Link to this post

    I finally solved it! It turned out to be quite tricky as I had some dependencies on the current page that where not satisfied when using FireCommand - it was simply to late when fired.

    So the correct approach and only way to set the initial start page, is to use FireCommand within OnPreRenderComplete:
    protected override void OnPreRenderComplete(EventArgs e)
        {
            base.OnPreRenderComplete(e);
            if (!IsPostBack)
            {
                RadDataPager1.FireCommand("Page", "5");
            }
        }

    In case OnPreRenderComplete is to late - i.e. data bindings on some other controls that would need the current page, it would be important to decouple it from RadDataPager.CurrentPageIndex and set a global variable for it. So you have the page either from the URL or in case of a post back the pager control itself.

    Here some code:

    int pageIndex = 0;
     
    protected void Page_Init(object sender, EventArgs e)
    {
        .....
         
        // set current page from URL - PART I
        if (!IsPostBack && string.IsNullOrEmpty(Request["p"]))
        {
            try
            {
                pageIndex = int.Parse(Request["p"]);
            }
            catch
            {          
            }
        }
     
        .....
     
    }
     
    protected override void OnLoad(EventArgs e)
    {
        // get current page from control
        if (IsPostBack)
        {
            pageIndex = RadDataPager1.CurrentPageIndex;
        }
    }
     
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);
     
        // set current page from URL - PART II
        if (!IsPostBack && string.IsNullOrEmpty(Request["p"]))
        {
            RadDataPager1.FireCommand("Page", pageIndex.ToString());
        }
    }
     
    protected void RadDataPager1_PageIndexChanged(object sender, RadDataPagerPageIndexChangeEventArgs e)
    {
     
        // when changing the page using the control in the page, get current(new) page from the event
        // OnLoad contains the OLD value
        if (IsPostBack)
        {
            pageIndex = e.NewPageIndex;
             
            // re data bind dependent controls for new page
            RadListView1.DataBind();
        }
    }
     
    protected void RadListView1_OnDataBinding(object sender, EventArgs args)
    {
        ...
                     
        // use pageIndex for current page
     
        ...
    }

    Hope this helps...

    Thanks to Telerik for clarification of the RadDataPager behavior and the idea with the global variable.

    Jens
Back to Top