Friday, 14 October 2016

Maintain Panel Scroll Position On Partial Postback ASP.NET




<script type="text/javascript">
            // It is important to place this JavaScript code after ScriptManager1
            var xPos, yPos; // Set X and Y positions
            var prm = Sys.WebForms.PageRequestManager.getInstance();

            function BeginRequestHandler(sender, args) {
                if ($get('<%=pnl_memgrid.ClientID%>') != null) {
                    // Get X and Y positions of scrollbar before the partial postback
                    xPos = $get('<%=pnl_memgrid.ClientID%>').scrollLeft;
                    yPos = $get('<%=pnl_memgrid.ClientID%>').scrollTop;
                }
            }

            function EndRequestHandler(sender, args) {
                if ($get('<%=pnl_memgrid.ClientID%>') != null) {
                    // Set X and Y positions back to the scrollbar
                    // after partial postback or full post back
                    $get('<%=pnl_memgrid.ClientID%>').scrollLeft = xPos;
                    $get('<%=pnl_memgrid.ClientID%>').scrollTop = yPos;
                }
            }

            prm.add_beginRequest(BeginRequestHandler);
            prm.add_endRequest(EndRequestHandler);

 </script>

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...