Search iEntry News

WebProASP
FlashNewz
DevWebPro











ASP.NET: Maintain Scroll Position After Postbacks

By Mads Kristensen
Expert Author
Article Date: 2006-12-19

To maintain the scroll position after postbacks is important for larger web pages in order to let the user know exactly what is going on.

It is good usability and something you would expect in modern web applications.

In ASP.NET 1.x you were able to do it simply by setting the SmartNavigation property to true on the page.

The problem with SmartNavigation we numerous and did more harm than good.

It was not cross-browser and it could mess up your own JavaScript.

That's part of the reason why it has been deprecated in ASP.NET 2.0.

Instead of SmartNavigation, ASP.NET 2.0 introduced the MaintainScrollPositionOnPostBack property, which does exactly what the name applies. It has a much smaller impact on the output and it is cross-browser compliant.

There are three ways of applying the property to a web page.

You can set it programmatically

Page.MaintainScrollPositionOnPostBack = true;

In the page declaration

<%@ Page MaintainScrollPositionOnPostback="true" %>

Or in the web.configs <system.web> section.

<pages maintainScrollPositionOnPostBack="true" />

This feature is an absolute must-have on large web pages built for postback scenarios.

The beauty of it is the simplicity and the low impact.

Comments

Tag:

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/



Newsletter Archive | Article Archive | Submit Article | Advertising Information | Resources | About Us | Contact

WebProASP is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal