• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1173
  • Last Modified:

Maintain scroll position of DIV through postback in masterpage

I have a master page with an update panel wrapping up the content template. In one of my pages  I have a grid view that is residing in a Div that utilizes the overflow method to produce scroll bars. I need to be able to retain the scroll position through post back. I have tried about a dozen 'solutions' to this (all JS) and none of them seem to work in conjunction with the master page. Please help! ><
1 Solution
The reason why all the solutions didn't work with the master page is because if you view the html of your page you will see the controls that you made runat="server" have kind of a strange ID (something like ctrl0_bla_ControlID) what you need to do is when referencing the control in javascript is use <%=ControlID.ClientID%> which will return that strange ID for you.
KnanceAuthor Commented:
I think by just posting here it makes the answer 10x easier to find.

As with most of these solutions after your script manager add :

                     <script type="text/javascript">
                         var xPos, yPos;
                         var prm = Sys.WebForms.PageRequestManager.getInstance();
                         function BeginRequestHandler(sender, args) {
                             try {
                                 yPos = $get('ctl00_MainContent_scroll').scrollTop;
                             catch (err) { }
                         function EndRequestHandler(sender, args) {
                             try {
                                 $get('ctl00_MainContent_scroll').scrollTop = yPos;
                             catch (err) { }

Check your source for your div id...mine was 'scroll' in code but as you see during runtime master page changes that a bit....hope this helps anyone else having issues.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now