Welcome to MSDN Blogs Sign in | Join | Help

News

  • These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified Terms of Use
Tip #75: Did you know…How to maintain scrollposition after post back?

When web pages are posted back to the server, by default user is returned to the top of the page. On a large web page, you might have a requirement to scroll down the user automatically to the last position on the page.

MaintainScrollPositionOnPostBack page property can be used to achieve this  in one of the following ways. 

  1. Application level: To set the property by default for all pages in the website, open web.config and add the attribute to the pages node.

    <pages maintainScrollPositionOnPostBack="true">

  2. Page Level: for a particular page, open the aspx and set the property

    <%@ Page MaintainScrollPositionOnPostback="true" ...

  3. Code level: to set the property programmatically

    Page.MaintainScrollPositionOnPostBack = true;

Hope this helps.

Deepak Verma
SDET | Visual Web Developer

Posted: Monday, June 08, 2009 12:43 PM by WebDevTools

Comments

What's New said:

When web pages are posted back to the server, by default user is returned to the top of the page. On

# June 8, 2009 9:08 PM

Rajeesh said:

Is this supported in all browsers? I know that it will work in IE and FF, what about safari?

Ta,

Rajeesh

# June 8, 2009 11:57 PM

Thanigainathan said:

Very veyr helpful tips.

Thanks,

Thani

# June 9, 2009 3:11 AM

Kunal - "the BOSS" said:

    Its so simple , but i just know today only having 2+ year of experience.

and i am searching for this kind of stuff.

sometimes this little code makes lots of help.

i dont believe that it is so simple to maintain scroll position after post back.

thanks.

# June 9, 2009 5:57 AM

Alireza said:

Thanks for this remarkable tip!

# June 9, 2009 8:08 AM

santosh said:

Yes, this is little code but so important

# June 9, 2009 9:43 AM

Greg said:

This is a good example why we do simple web page based applications now.  The older heavyweight GUI .NET 2.0 era applications we developed are much harder and costly to maintain given that we made the mistake of attempting to mimic a desktop winforms application in ASP.NET web pages.  Our web apps are lightweight GUI pages and we use silverlight for our heavyweight winforms like GUI applications.  

Our business users/analysts are used to MS Word interactivity and try to get it into our web applications without considering the greatly increased cost and failure risk that level of interacvtivity brings to an ASP.net application.

# June 9, 2009 11:04 AM

WebDevTools said:

Hi Rajeesh,

Thanks for you feedback.

>>>>>>>>>>>>>> I know that it will work in IE and FF, what about safari?

A workaround for Safari can be found at http://forums.asp.net/p/1094179/1651390.aspx .

Thanks,

Deepak

# June 9, 2009 1:59 PM

sun.Lei said:

在ASP.NET中PostBack后保持页面的位置(滚动条位置),在内容多的页面中非常有用(长页面).

# June 21, 2009 10:09 AM

KidYang said:

Whenwebpagesarepostedbacktotheserver,bydefaultuserisreturnedtothetopofthepage.On...

# June 21, 2009 9:55 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker