ASP.NET FAQ - maintain page scroll position after a page postback
I found the answer to an ASP.NET question that I've been asked literally about 10 times.
How do you maintain page scroll position after a postback?
Say you've got some really long page, perhaps with some huge Control -- like, say, a huge, edit-enabled GridView. Someone clicks a link halfway down that page (like, say, the "Edit" link on one of the later entries in that huge GridView). It generates a postback, and the page get refreshed to its *top* instead of half-way down.
If you want, instead, to maintain the page scroll on a postback, just set the MaintainScrollPositionOnPostback property on the Page. You can do this declaratively (in your aspx Page directive) like so:
<%
@ Page MaintainScrollPositionOnPostback="true" ... %>
If that's too heavy-handed a solution (i.e. you don't want to maintain scroll position for all postbacks), you can use the solution found on this page.
Comments
- Anonymous
January 12, 2006
Tried it:
The 'MaintainScrollPositionOnPostback' attribute is not supported by the 'page' directive. - Anonymous
January 17, 2006
Which version of ASP.NET are you using? I'm using 2.0 (in Visual Studio 2005) - Anonymous
January 20, 2009
PingBack from http://www.hilpers-esp.com/430333-mantener-el-scroll-al-hacer