Save RadGrid scroll position when leaving page

Thread is closed for posting
6 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 04 Mar 2007 Link to this post

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    4.5.2 and later


    2008.1.415 and later
    .NET version

    2.0 and later
    Visual Studio version

    2005 and later
    Programming language

    C#, Javascript
    Browser support

    all supported by RadGrid for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX

    To convert code from posted projects Telerik online converter

     
    PROJECT DESCRIPTION

    Some scenarios require leaving the page and when getting back to it the grid to be scrolled to the position where it has been before leaving the page. A cookie can be used to store the grid scroll position so it can be restored when entering the page again. r.a.d.grid's client event OnScroll can be used to save the current grid scroll position. The element to be scrolled when loading the page is grid's data div, that is the grid ID, followed by _GridData.

    The javascript code used follows:

    function SetScrollPosition() 
        { 
            var y = document.getElementById('<%= RadGrid1.ClientID%>_GridData').scrollTop; 
            document.cookie = "divPos=!^^->" + y + "<-^^!";  
        }  
        window.onload = function() 
        { 
            var cook = document.cookie;  
            if(cook.indexOf("!^^->")!=0) 
            {  
                var start = cook.indexOf("!^^->");  
                var end = cook.indexOf("<-^^!");  
                var pos = cook.substring(start+5, end);  
                window.setTimeout(function() 
                { 
                    document.getElementById('<%= RadGrid1.ClientID%>_GridData').scrollTop = pos;  
                }, 0); 
            } 
        } 
  2. Jeff P
    Jeff P avatar
    37 posts
    Member since:
    Mar 2007

    Posted 28 Sep 2007 Link to this post

    How would this work in a Master page scenerio?
  3. Nikita Gourme
    Nikita Gourme avatar
    318 posts
    Member since:
    May 2006

    Posted 04 Oct 2007 Link to this post

    jalmto, have you tested the same javascript solution in master page scenario? At first sight there should not be any significant difference whether you put the grid on standard web form/user control, master or content page.

    Nikita
  4. Jeff P
    Jeff P avatar
    37 posts
    Member since:
    Mar 2007

    Posted 10 Oct 2007 Link to this post

    The problem is with the onload function.  It will run for every content page and then generate an error when the grid does not exist.  How would you run the onload function only when the grid is present on the content page?
  5. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 11 Oct 2007 Link to this post

    Hello jalmto,

    Having this in master page should not produce any difference. Please, find attached an updated version. Two pages and a master page are added. Use Default3.aspx as start page.

    Kind regards,
    Ves
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 23 Feb 2008 Link to this post

    You can find attached to the initial message a project, migrated to RadControls "Prometheus". The javascript code is very close to the original:

        function SetScrollPosition() 
        { 
            var y = $get('<%= RadGrid1.ClientID%>_GridData').scrollTop; 
            document.cookie = "divPos=!^^->" + y + "<-^^!";  
        }  
        window.onload = function() 
        { 
            var cook = document.cookie;  
            if(cook.indexOf("!^^->")!=0) 
            {  
                var start = cook.indexOf("!^^->");  
                var end = cook.indexOf("<-^^!");  
                var pos = cook.substring(start+5, end);  
                window.setTimeout(function() 
                { 
                    $get('<%= RadGrid1.ClientID%>_GridData').scrollTop = pos;  
                }, 100); 
            } 
        } 

Back to Top