Maintaining scroll position in ASP.NET 2.0

08.20.2007

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:

1
<%@ 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.

Tags: ,


Comments

09.28.2007 / Rachel said:

Does this new feature work without bugs? Microsoft has had the same feature in previous versions of ASP.Net. It was called something like SmartNavigation, but it was so incredibly buggy that it wasn’t usable in serious applications.

09.28.2007 / Aaron Hardy said:

Hey Rachel, this feature seems to work without a hitch. I’ve used it several times without seeing any problems (Firefox and IE) and I personally haven’t read anything on the web about it having bugs. Again, this is .NET 2.0. Thanks for commenting!


Leave a Comment

Your email address is required but will not be published.




Comment