Maintaining scroll position in ASP.NET 2.0

While I have often vented my frustrations with how difficult it can be working with DHTML in ASP.NET, Microsoft has taken a great step in helping developers make the transition to their primarily postback-based framework. To explain, one reason why I love DHTML so much is that I hate having to post back to the server just to dynamically add/remove a text box or show/hide a particular div. What makes posting back worse is that when you get the regenerated page, the user’s browser jumps back to the top of the page. In other words, if my page has a bunch of content, the user has scrolled down and is looking at the bottom of the page, and then the user clicks some link or button that has to post back to the server to regenerate the same page for just a slight user interface modification, the user’s browser jumps back to the top of the page. It’s really pretty annoying. Well if you don’t want to jump through all the hoops of using DHTML in .NET but you don’t want to drive your users crazy, you should quickly become acquainted to a property new to .NET 2.0: MaintainScrollPositionOnPostback

Here’s how it’s implemented:

<%@ Page MaintainScrollPositionOnPostback="true" ... %>

That’s it. Just add the property to your page directive and every time there’s a postback the user’s scroll position will stay put. This makes for a much more seamless interaction for your users.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.