CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    Maintaining scroll position on Treeview

    Hi All,

    I found this great article on maintaining scroll position

    http://www.codeguru.com/csharp/.net/...le.php/c12869/

    It works a treat if your not using master pages, but with a master page, it seems not to work. The reason being it wants to place an onload event in the <body> section, but of course there is no <body> section in the pages that use a master page.

    I thought I'd be smart and place it in the master page <body> but this didn't work, presumably because the masterpage isn't getting posted back.

    Anybody have any ideas how to maintain the scroll position when the treeview is in a container control where the page has a master page?

    ASP 2.0
    If you find my answers helpful, dont forget to rate me

  2. #2
    Join Date
    Sep 2004
    Posts
    65

    Re: Maintaining scroll position on Treeview

    You can use the following javascript function to add scripts to the body onload event. Just inject that javascript into your page somewhere... I know this works with IE6, but I haven't tested on any other browsers. Insert a script statement after your treeview something like this
    Code:
    <script language="javascript">addLoadScript('LoadEvent');</script>
    the function:
    Code:
      function addLoadScript(script)
      {
    	if (window.onload == null)
    	{
    		window.onload=new Function(script);
    	}
    	else
    	{
    	
    		var oldscript = window.onload.toString();
    		if (oldscript.substring(0,8) == 'function')
    		{
    			var start = oldscript.indexOf('{');
    			var end = oldscript.lastIndexOf('}');
    			oldscript = oldscript.substring(start + 1, end);
    			oldscript = Trim(oldscript);
    			
    			if  (oldscript.charAt(oldscript.length - 1) != ';')
    			{
    				oldscript = oldscript + ';';
    			}
    			window.onload = new Function(oldscript + script);
    		}
    	}
    }
    
    function Trim(sInString) 
    {
    	sInString = sInString.replace( /^\s+/g, "" );
    	return sInString.replace( /\s+$/g, "" );
    }
    You can view my thread about scrolling and onload here
    http://www.codeguru.com/forum/showthread.php?t=429177

    Hope this helps.

    -Ranthalion

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured