Maintaining Page Scroll Position

Maintaining Page Scroll Position

Recently working here we were facing an interesting problem.  We have some complex forms for Careers where user is required to update stuff as his resume.  We found out that we cannot use the Upload Control inside update panel so we have to remove the panel which resulted in post back.  Our update buttons are in the end of the page so after post back it goes back to the top of the page and cannot maintain its position.  One of my team mates found the solution below.   I do not know the source so if it is already posted any where please don’t mind.

Page.MaintainScrollPositionOnPostBack Property

 

This property gets or sets a value indicating whether to return the user to the same position in the client browser after postback. This property replaces the obsolete SmartNavigation property.

When Web pages are posted back to the server, the user is returned to the top of the page. On long Web pages, this means that the user has to scroll the page back to the last position on the page.

When the MaintainScrollPositionOnPostback() property is set to true, the user is instead returned to the last position on the page.

use it in page.aspx

<
asp:Page MaintainScrollPositionOnPostBack="True|False" />

OR in page_Load :

Page.MaintainScrollPositionOnPostBack = true;

 

use it in UserControl.ascx

 

Parent.Page.MaintainScrollPositionOnPostBack = true;

Jerry

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s