Link to home
Start Free TrialLog in
Avatar of Knance
Knance

asked on

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! ><
ASKER CERTIFIED SOLUTION
Avatar of crisco96
crisco96
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Knance
Knance

ASKER

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();
                         prm.add_beginRequest(BeginRequestHandler);
                         prm.add_endRequest(EndRequestHandler);
                         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) { }
                         }
                        </script>


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.