Tuesday, January 30, 2007

ASPNET: Maintain Page position on Postback

When you have a long web page, you might want to maintain the page position after the post back so that tbe user does not have to scroll down to the page again. This is a very important usability issue.

In ASP.NET 1.1, you can achieve this using the SmartNavigation page directive:

<%@ Page Language="C#" SmartNavigation="true"%>

However, SmartNavigation require IE 5.5 or above.

ASP.NET 2.0 introduce a new page directive call MaintainScrollPositionOnPostback which achive the same result.

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" %>

I tested MaintainScrollPositionOnPostback in both IE and Firefox and it work prefectly in both browser. Better still, you can enable this for all web pages in your web site by setting it in the web.config under <pages> element.