Showing posts with label Maintain Panel/Div Scroll Position in UpdatePanel On Postback ASP.NET. Show all posts
Showing posts with label Maintain Panel/Div Scroll Position in UpdatePanel On Postback ASP.NET. Show all posts

Saturday, April 23, 2016

Maintain Panel/Div Scroll Position in UpdatePanel On Postback ASP.NET


  <form id="form1" runat="server">  
  <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />  
   <script type="text/javascript">  
     // It is important to place this JavaScript code after Ajax ScriptManager / Toolkit Script  
     var xPos, yPos;  
     var prm = Sys.WebForms.PageRequestManager.getInstance();  
     function BeginRequestHandler(sender, args) {  
       if ($get('<%=Panel1.ClientID%>') != null) {  
        // Get X and Y positions of scrollbar before the partial postback  
        xPos = $get('<%=Panel1.ClientID%>').scrollLeft;  
       yPos = $get('<%=Panel1.ClientID%>').scrollTop;  
     }  
   }  
   function EndRequestHandler(sender, args) {  
     if ($get('<%=Panel1.ClientID%>') != null) {  
        // Set X and Y positions back to the scrollbar  
        // after partial postback  
        $get('<%=Panel1.ClientID%>').scrollLeft = xPos;  
        $get('<%=Panel1.ClientID%>').scrollTop = yPos;  
      }  
    }  
    prm.add_beginRequest(BeginRequestHandler);  
    prm.add_endRequest(EndRequestHandler);  
  </script>  
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
   <ContentTemplate>  
    <asp:Panel ID="Panel1" runat="server" Height="300px">  
     <%--Data--%>  
    </asp:Panel>  
   </ContentTemplate>  
  </asp:UpdatePanel>  
 </form>