Wednesday 22 February 2012

How to maintain ScrollBar position on postbacks in ASP.NET Page?


After user clicks on postback controls, ASP.NET web page is reloaded in the browser and scroll position is set to the top of the page.

If your pages are high/long and controls that cause postback are placed on the bottom it can be really annoying for users to manually scroll down after every postback.

Fortunately, this can be easily solved using the Page.MaintainScrollPositionOnPostBack property like this:

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

After the postback and reload of the page, the previous scroll position will be restored.

NOTE: this only works in .Net Framework 2.0 and higher!

No comments :