ASP.NET - MaintainScrollPositionOnPostback fails.

Asked By RAJESH VEMUNOORI on 27-Apr-13 10:31 AM
Hi All,

I have a ASP panel and a div within it. the div is defined in a way  <div style="overflow-x: hidden; overflow-y: scroll; height: 300px"> to have scroll within the div. I need to maintain the scroll position in the div if any event is occurred. I've tried using MaintainScrollPositionOnPostback = "true" but this fails. and also used the below javascript which also failed to do so

<asp:ScriptManager runat="server" EnablePartialRendering="true" ID="SM1">

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

Any alternative to get this?
Appreciate your help..

Robbe Morris replied to RAJESH VEMUNOORI on 27-Apr-13 11:12 AM
MaintainScrollPositionOnPostback definitely won't work against an html element in the page.  You may have to wrap your JavaScript up in a function and make sure it gets executed after the DOM is completely loaded.  You might want to set a timer up to fire say 25 milliseconds after the page/DOM loads, execute your function, and then disable the timer.

I've never need to do this.  So, I'm just throwing out some ideas.