Scroll to top of page on PageIndexChanged?

6 posts, 0 answers
  1. Tony
    Tony avatar
    22 posts
    Member since:
    Jun 2005

    Posted 22 Jan 2009 Link to this post

    Hi,

    I have a radgrid with paging at the top and bottom and want the page to scroll back to the top when the page is changed (expecially from the bottom paging links).

    I have tried adding the following code, but something inside the radgrid code is stopping it from working as it does on a regular asp.net button.

    Protected Sub RadGrid1_PageIndexChanged(ByVal source As ObjectByVal e As Telerik.Web.UI.GridPageChangedEventArgs) Handles RadGrid1.PageIndexChanged  
            ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "Scroll""scroll(0,0); "True)  
        End Sub 

    Is there another way of achieving this?  Or a way of getting my code to work?

    Thanks in advance
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Jan 2009 Link to this post

    Hi Tiny,

    Have you set the SaveScrollPosition  property of the Grid to true? If so try setting it to false and see whether it helps.

    ASPX:
    <ClientSettings> 
               <Scrolling  UseStaticHeaders="true" AllowScroll="true" SaveScrollPosition="false" /> 
      </ClientSettings> 


    Thanks
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tony
    Tony avatar
    22 posts
    Member since:
    Jun 2005

    Posted 23 Jan 2009 Link to this post

    Hi Shinu,

    Thanks for your reply. Unfortunately your suggestion does not help me as I am not using the built in RadGrid scrolling, but allowing the grid to fill the area it needs and just using the main page/browser scrolling, see - http://www.brightandbright.co.uk/SaleList.aspx.

    I don't mind if the page jumps back to the top of the grid or the whole page.

    Thanks,

    Tony.
  5. bwood
    bwood avatar
    12 posts
    Member since:
    Jul 2007

    Posted 25 Jun 2010 Link to this post

    He meant that he is using Ajax. When you click for the next or previous page in the pager, the page stays scrolled down to the bottom of the page. It would be great if there was a way to make it automatically scroll to the top of the again. I'm trying this test but I can't get the javascript to fire:

    protected void rg_PageIndexChanged(object sender, GridPageChangedEventArgs e)
     {
        ScriptManager.RegisterStartupScript(this, typeof(System.Web.UI.Page), "ui", "alert('true')", true);
     }



  6. Tony
    Tony avatar
    22 posts
    Member since:
    Jun 2005

    Posted 25 Jun 2010 Link to this post

    Hi Ksieburg,

    This was a while ago, but I think I remember finding a solution.  Try adding the following JavaScript to your page...

    <script type="text/javascript" language="javascript">  
            // Catches events fired by the RadGrid (paging) and jumps page to the top   
            var postbackElement;  
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);  
            Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);  
            function beginRequest(sender, args) {  
                postbackElement = args.get_postBackElement();  
            }  
            function pageLoaded(sender, args) {  
                if (typeof (postbackElement) === "undefined") {  
                    return;  
                }  
                // Uses the MasterTable ClientID  
                if ((postbackElement.id) === "ctl00_cp1_RadGrid1_ctl00") {  
                    window.scrollTo(0, 0);  
                }  
            }  
    </script> 

    Obviously, you need to replace ctl00_cp1_RadGrid1_ctl00 with the Client ID of your RadGrid.

    Let me know how you get on,

    Tony.
  7. bwood
    bwood avatar
    12 posts
    Member since:
    Jul 2007

    Posted 25 Jun 2010 Link to this post

    Thanks, Tony!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017