Thursday, March 22, 2012

Maintaining the scroll position of mutiple Panels in a single Page

Hi All,I have a requirement that the position of scrolling in all the panels in a single page should be maintained across post backs.I checked on a few post here which primarily discuss how to do this for a single panel.The solution usually hovers around the technique of saving the scroll top in a hidden variable and setting it back to the div element after each postback.I there a way to accomplish this for mutiple panels without introducing a hidden field for each of the panels.Thanks You,Prabu G

If you are using ASP.NET 2.0 you can set theMaintainScollPositionOnPostback="true" in your @.Page declaration.


Thanks for the reply.

But that way, only the main scroll bar in the page is being maintained. I want the same functionality in the two panels in the page as well.


Hi All,

I finally solved this, thanks to the forum members and all the others who helped.

The solution is to store the scroll position of the panels (onscroll event), and then set the scroll postion after the postbacks.

Below is the javascript code I employed, perhaps there is a better method.

//Add this to div - onscroll="getScrollTop(divName,aHiddenFieldName)"//Add this to page load - setScrollTop(divName,aHiddenFieldName)//For more that one panel, have a separate hidden field for each panel and pass the respective values//function to set the div scroll top from the passed hidden filed's valuefunction setScrollTop(divControlId, hiddenControlId){if ( document.getElementById(divControlId) !=null && document.getElementById(hiddenControlId) !=null ){document.getElementById(divControlId).scrollTop = document.getElementById(hiddenControlId).value;}}//function to save the div scroll top from the passed hidden filed's valuefunction getScrollTop(divControlId, hiddenControlId){if ( document.getElementById(divControlId) !=null && document.getElementById(hiddenControlId) !=null ){document.getElementById(hiddenControlId).value = document.getElementById(divControlId).scrollTop;}}

Hops this will be of any help to others

0 comments:

Post a Comment