Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Maintain scrollposition on postback

Modified: 2010/02/24 11:11 by erik - Categorized as: ASP.NET, HTML, Javascript
The System.Web.UI.Page object has a property called 'MaintainScrollPositionOnPostback'. When you set this property to true, then the framework will insert javascript into the rendered page which maintains the browser scroll position for postbacks.

Without MaintainScrollPositionOnPostback, when a user visits a web page that is "taller" than the browser window, they have to scroll down to see the content further down on the page. If the user then clicks on a Button or performs some other action that causes a postback, the browser reloads the page and, by default, returns to the home scroll position at the top of the page, requiring the user to scroll back down to the location they were viewing when the postback occurred. To have the user's scroll position remembered across postbacks, simply set MaintainScrollPositionOnPostback to True, which can be done on a page-by-page basis or applied to all pages by configuring this option through Web.config.

Click here to view the original post.

Usage example in a page directive

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Newslisting.aspx.cs" Inherits="Website.Evident.Newslisting" MaintainScrollPositionOnPostback="true" %>

 © Evident Interactive BV