Question

I have one update panel inside which I have datalist.

This update panel triggers every 1 second to retrieve the data from db.

I have kept this update panel inside a vertical scroll enabled div tag.

But when I get new data, the scroll bar is not adjusting automatically !!!

I have tried maintainscrollback option but its not working.

Is there any option to maintain the scroll bar to it original position after the updatepanel triggers?

Was it helpful?

Solution

Here is what I prefer to avoid JavaScript, which needs to adjust scroll position each and every refresh/update...

I guess you must have designed page like below

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
    <ContentTemplate>
        <div style="height: 400px/300px; overflow-y:scroll;"> 
            <asp:DataList ID="DataList1" runat="server">
                ....
            </asp:DataList>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

Change it to some thing like this should take care of scroll issue

<div style="height: 400px/300px; overflow-y:scroll;"> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
        <ContentTemplate>
                <asp:DataList ID="DataList1" runat="server">
                    ....
                </asp:DataList>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

OTHER TIPS

Please try this:

<script>
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_beginRequest(function(){
     window.dTop = document.getElementById('divIdHere').scrollTop;
  });

  prm.add_endRequest(function(){
       setTimeout(function(){
         document.getElementById('divIdHere').scrollTop = window.dTop;
      },100);
  });
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top