MaintainScrollPositionOnPostBack | Rickard Andersson

MaintainScrollPositionOnPostBack

At work, I’m currently in the process of migrating a relatively large (~30,000 lines of code) ASP.NET 1.1 project over to 2.0. While doing this, I have picked up a few cool things in ASP.NET 2.0. One of these is the Page.MaintainScrollPositionOnPostBack property. Instead of trying to describe what it does, I’ll copy and paste from MSDN:

When Web pages are posted back to the server, the user is returned to the top of the page. On long Web pages, this means that the user has to scroll the page back to the last position on the page.

When the MaintainScrollPositionOnPostBack() property is set to true, the user is instead returned to the last position on the page.

Now, I’m sure the behind-the-scenes implementation is this isn’t as pretty or as elegant as something you could cook up yourself, but dammit, it just works. In my case, the app I’m working on is for an intranet where we have full control over the browsers being used and accessibility isn’t a big issue. The app itself has lots of really large forms with tables, drop-down lists and submits. The ability to have users submitted back to the exact spot on the page where they submitted the form is a godsend.

Post a Comment

Comments are moderated. Your email is never published nor shared.