Hosam Kamel's Blog

Sponsors

News


Follow HosamKamel on Twitter

Blogroll

Maintain scroll position after postbacks in ASP.NET 2.0

To maintain the scroll position for the large web page you can use on of these methods :

1- use Web.config page section <pages maintainScrollPositionOnPostBack="true" />

: this will maintains the scroll positions for all the web site pages.

2- in the page declaration  <%@ Page MaintainScrollPositionOnPostback="true" %> : this will maintains the scroll position for this page only.

3- programmatically from code behind System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;  : this will maintains the scroll position for this page only (the same as page declration).

Posted: Sep 07 2007, 11:07 PM by Hosam Kamel | with 36 comment(s) |
Filed under:

Comments

Vikram said:

But this does not work well when we have web user controls.

# September 8, 2007 12:48 AM

Hosam Kamel said:

Hi Vikram, I have read your comment on 'Scott on Writing' blog scottonwriting.net/.../10638.aspx  about this issue but unfortunately I'm personally didn't trying to test this issue … but I will try to play for a while with it and will back to you.

# September 8, 2007 6:14 AM

Makarios said:

Interesting...

# September 22, 2007 8:38 PM

Tataki said:

Sorry :(

# September 23, 2007 8:26 AM

Ioannes said:

interesting

# September 23, 2007 11:59 AM

Philippos said:

Cool!

# September 24, 2007 5:57 AM

Nico said:

Cool...

# September 24, 2007 7:03 AM

Eleni said:

Cool.

# September 24, 2007 2:53 PM

Giannis said:

Cool.

# September 24, 2007 5:07 PM

Vassilis said:

Cool!

# September 25, 2007 12:47 PM

Marios said:

Interesting...

# September 25, 2007 2:34 PM

Lazaros said:

Cool...

# September 25, 2007 3:22 PM

Zeus said:

Nice!

# September 25, 2007 10:21 PM

Titos said:

Nice...

# September 26, 2007 2:28 AM

Costas said:

Nice

# October 16, 2007 11:33 AM

Ivan said:

Nice

# October 17, 2007 5:02 AM

Ahmed said:

Perfect, thanks a bunch!

# November 27, 2007 8:53 AM

Aristofanes said:

Nice post, it really was useful to me.

Thx!

# April 4, 2008 1:01 PM

Haithem said:

I used  MaintainScrollPositionOnPostback="true" in order to maintain the position of the scrollbar of a treeview included in an ajax control but nothing happened

Do u have another solution ?

# April 8, 2008 10:03 AM

Hosam Kamel said:

# April 13, 2008 8:05 AM

Sundeep said:

Thats a wonderful option. Got onto google to search for a huge code, which turned out to be a tag on page directive! awesome!

# July 24, 2008 5:18 PM

SOmia said:

Thanks for help

# August 15, 2008 7:23 AM

Lata said:

This is such a nice & easy solution....Thanks..

# October 4, 2008 5:39 AM

AK said:

you mention that if set the value on Web.config file it would maintain its position. i tried it but it did not work? any reason why?

# October 9, 2008 5:07 PM

Hosam Kamel said:

Yes , it should did so unless you've some controls or other things prevent this

check MSDN : msdn.microsoft.com/.../950xf363.aspx

let me know if it is disabled allover the pages or in certain pages ? also are you using web project or web site ?

# October 10, 2008 7:50 AM

devendra0211 said:

not work for me............giving error

# December 17, 2008 2:06 PM

santhosh said:

its nice and easiest one

# February 3, 2009 2:27 AM

tfh said:

Works great as advertised !

# March 5, 2009 10:52 AM

Button e posizionamento | hilpers said:

Pingback from  Button e posizionamento | hilpers

# May 13, 2009 2:07 PM

maung aung aung said:

Solved my problem.

# July 11, 2009 9:17 AM

Bobby Strain said:

It works well with earlier versions of IE. But it fails with the latest version and also with Firefox. Is there a new fix?

# August 8, 2009 11:18 AM

Hosam Kamel said:

@Bobby Strain please try compatibility view in IE 8 it should fix your problem if so you can force his compatibility mode through a browser meta tag

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

hope it helps

# August 27, 2009 6:38 AM

Hasu said:

the code given by you is perfectly fine when i refresh the page, but what i want is that if any submit button clicked then the page should remain at its position

user should fill that page has refreshed or autopostback

pls any idea,

thanks

# October 3, 2009 5:47 AM

evoMan said:

Hi,

I am using the AJAX Ad rotator control from the AJA tool Kit for dot net and Every time the adds rotate the scroll bar postion either jumps up or down in IE 6,7,8. Firefox works fine. aspspider.ws/.../cms.aspx

I have already tried maintainScrollPositionOnPostBack="true" in the web config, the page itself and programatically with no success. Any thoughs or help will be much appreciated.

Interestingly enough there appears no issue when run through visual studio 2008 in the development environment but the issue exhibits itself under local host or the demo site described above.

# October 8, 2009 7:36 PM

Dilip said:

Thanks a lot

# November 26, 2009 4:05 AM

KK said:

Intresting.. Thank you

# December 30, 2009 3:09 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)