Maintain Scroll Position On After Postback in Asp.Net 2.0 3.5

In this example i'm explaining different methods of Maintaining Scroll Position On/After Postback In Asp.Net 2.0,3.5,4.0 Web pages or Applications.


Maintain scroll position after postback
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;


Method3.

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.

If you like this post than join us or share

7 comments:

Anonymous said...

hi just registered ,, tina


Anonymous said...

this does not work at all


Unknown said...

@Avobe: What's not workingfor you ?, what error you are getting ?


Anonymous said...

it does not work, when page reload, it goes to top of the page for IE8.


Sandra said...

Doesn't work in Chrome - it may be only for IE browser.


Unknown said...

@Sandra: Yes this method doesn't work in Google Chrome.

Read Asp.Net Maintain ScrollPosition OnPostBack In Chrome to know how to maintain scroll position on postback in Google Chrome browser.


Anonymous said...

Add it to an update panel inside of a tab container, on an aspx page with a master page. Then you are doing something!!! lol


Find More Articles