This is a migrated thread and some comments may be shown as answers.

Scroll to top of page on PageIndexChanged?

5 Answers 361 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 2
Matt asked on 22 Jan 2009, 08:35 PM
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

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Jan 2009, 04:34 AM
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
0
Matt
Top achievements
Rank 2
answered on 23 Jan 2009, 09:51 AM
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.
0
bwood
Top achievements
Rank 1
answered on 25 Jun 2010, 03:46 PM
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);
 }



0
Matt
Top achievements
Rank 2
answered on 25 Jun 2010, 04:25 PM
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.
0
bwood
Top achievements
Rank 1
answered on 25 Jun 2010, 08:22 PM
Thanks, Tony!
Tags
Grid
Asked by
Matt
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Matt
Top achievements
Rank 2
bwood
Top achievements
Rank 1
Share this question
or