5

I have a site that uses master pages, the only content that changes is a Div in the centre of the page.

Is there a way that I can persist the scroll position of the page between postbacks? I'm thinking that it might be possible because all pages are using the same Master Page, if not is there some other way to do this?

Thanks

Fermin
  • 34,961
  • 21
  • 83
  • 129

3 Answers3

4

Try adding this.Page.MaintainScrollPositionOnPostBack = true; somewhere in the masterpage code behind (for example page load)

Stilgar
  • 22,354
  • 14
  • 64
  • 101
  • Tried this and it doesn't work, i've added it into the web.config and also tried adding in the individual pages but still no joy. Any idea why that would be? – Fermin Jun 16 '09 at 08:57
  • I believe this will only work if you are posting to the same page (i.e. doing a postback). If you are going to another page that uses the same master page (for example through hyperlinks) the scroll position will not be maintained using this solution. – Stilgar Jun 16 '09 at 11:52
  • 2
    A bit late, but might be useful to others: it worked for me when I added that line inside the `OnInit` eventhandler of the masterpage (before calling `base.OnInit(e)`). I think it has to be set before the page loads for it work (hence why OnInit works). – Tom van Enckevort Jul 03 '12 at 10:44
2

Try this: http://radio.javaranch.com/pascarello/2005/07/18/1121709316718.html

Andrew Siemer
  • 10,166
  • 3
  • 41
  • 61
0

4guysfromrolla.com has an article where a custom server control is created to maintain scroll position across postbacks. Maybe it could be of some use to you.

Malice
  • 3,927
  • 1
  • 36
  • 52