Maintain Scroll Position After Postback in Asp.Net

Aug 29, 2011 Posted by Lara Kannan

In this example i'm explaining different methods of maintaining scroll position after postback in asp.net 2.0, 3.5 & 4.0 web pages or applications.



Method : 1

Write below mention directive in page directive section of html source of aspx page to maintain scroll position of only one page or selected pages rather then whole web application.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 

MaintainScrollPositionOnPostback="true" Inherits="_Default" %>



Method : 2

To maintain scroll position programmatically use code mentione below.

System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;



Method : 3

To maintain scroll position application wide or for all pages of web application we can write below mentioned code in pages section of web.config file so that we don't need to add page directive in each and every page.

<pages maintainScrollPositionOnPostBack="true">



Hope this helps.

Share
Labels:
  1. this code is not working properly please help

    MaintainScrollPositionOnPostback="true" Inherits="_Default" %>


Post a Comment