Solved

MaintainScrollPositionOnPostback doesn't work in Ajax postback

Posted on 2008-10-22
3
1,485 Views
Last Modified: 2012-05-05
I have a none Ajax aspx page which worked with MaintainScrollPositionOnPostback where after a postback, the page came back at the same scroll position. When I converted the page to use Ajax, the page always scrolls to the top.

Is there a way to maintain scroll position after an asynchronous postback?
0
Comment
Question by:jentel2
3 Comments
 
LVL 10

Accepted Solution

by:
Bane83 earned 500 total points
ID: 22785963
Add this to the end of your page.
<script type="text/javascript">
	var scrollTop;
 
	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
 
	function BeginRequestHandler(sender, args) 
	{
		scrollTop = document.body.scrollTop;
	}
 
	function EndRequestHandler(sender, args)
	{
		setTimeout(EndRequestHandler1, 0);
	} 
	
	function EndRequestHandler1(sender, args)
	{
		document.body.scrollTop = scrollTop;
	} 
	
</script>

Open in new window

0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question