Maintaining Vertical Scroll Position - Fixed!

Mar 28, 2009 at 1:32 AM
Hi All!

Don't you hate it when you click on a button on the very bottom of a page and the page scrolls to the top after refreshing? Then you have to scroll down again.

This page discusses a way to keep the vertical scroll position on a page:

The solution works by itself but I am having trouble integrating it with my BE web page.

Anybody has run into this before?

Mar 28, 2009 at 4:31 AM
Which page in BE are you trying to do this for?  Incidentally, the method described in that article works, but since ASP.NET 2.0, there's also a MaintainScrollPositionOnPostback property for pages.  It can be set in the <%@ Page %> directive ...

<%@ Page MaintainScrollPositionOnPostback="true" %>

or in the code behind ...

this.MaintainScrollPositionOnPostBack = true;

But a number of pages in BE are already setup to do AJAX postbacks.  For AJAX postbacks, the page doesn't automatically scroll back up to the top.  Examples of this are when you leave a comment, fill out the Contact page, enter your email address in the Newsletter widget, and a number of other places.
Mar 28, 2009 at 4:53 AM

The MaintainScrollPositionOnPostback property of the page fixed my issue.

It was a custom page that I added to my Blog.

I hope this helps others too.