Solved

Maintain scroll position of DIV through postback in masterpage

Posted on 2010-09-22
2
1,133 Views
Last Modified: 2012-05-10
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! ><
0
Comment
Question by:Knance
2 Comments
 
LVL 15

Accepted Solution

by:
crisco96 earned 500 total points
ID: 33736121
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.
0
 

Author Comment

by:Knance
ID: 33736205
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question