Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I'm new to ASP.net; I'm having a problem with autopostback on a dropdown list.
Each time a selection is made, the autopostback fires as it should BUT the page always scrolls to the top.
 
I'm using Firefox 17.0.1 and have also tested on Chrome 23.0.1271.97 m; javascript is enabled.
 
I have tried:
 
Page.MaintainScrollPositionOnPostBack = true;
in the code behind (Load event), also in MasterPage code behind
 
maintainScrollPositionOnPostback="true"
in the page declaration
 
<pages maintainScrollPositionOnPostBack="true" />
in the web.config
 
.Focus()
on various controls on the page
 
all to no effect. The problem persits. I can see nothing in the MasterPages or the current page to cause this.
 
Please help..
Posted 4-Jan-13 16:41pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I guess you are missing use of SetFocus along with MaintainScrollPosition.
 
2 options:
1. try MaintainScrollPosition page attribute with SetFocus method. Refer: MSDN: Page.MaintainScrollPositionOnPostBack Property [^] OR
 
2. you can keep track of the scroll position on client side before the onchange event fires. Restore the scroll position back to what you stored last time after the page refresh. Refer: Part of the article provides way to do it[^]
 
Earlier, Smartnavigation = true property was used. But now, option 1 is the new one.
[BrowsableAttribute(false)]
[ObsoleteAttribute("The recommended alternative is Page.SetFocus and Page.MaintainScrollPositionOnPostBack. http://go.microsoft.com/fwlink/?linkid=14202")]
public bool SmartNavigation { get; set; }
Refer: MSDN: SmartNavigation[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100