Solved

MaintainScrollPositionOnPostback doesn't work in Ajax postback

Posted on 2008-10-22
3
1,476 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code works but how can I download the file? 20 67
asp.net mvc input file 2 32
Run time Error 4 34
Where can I ask about my ASP.NET MVC project? 6 6
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now