Sharath Quad

Sharath Quad

  • NA
  • 9
  • 4.3k

How to Maintain Scroll position after asynchronous postback

Apr 29 2014 12:42 AM
I have a child page with the nested master means 2 master pages inherit one from another and in that child page I have all user controls only.
So in my case I have to maintain a scroll position of a child page after async post back of user control list box.
I have tried:

MaintainScrollPositionOnPostback="true" 

 <script type="text/javascript" >
           var xPos, yPos;
           var prm = Sys.WebForms.PageRequestManager.getInstance();
           prm.add_beginRequest(BeginRequestHandler);
           prm.add_endRequest(EndRequestHandler);
           function BeginRequestHandler(sender, args) {
               xPos = document.getElementById("<%=UpdatePanel1.ClientID %>").scrollLeft;
               yPos = document.getElementById("<%=UpdatePanel1.ClientID %>").scrollTop;
           }
           function EndRequestHandler(sender, args) {
               document.getElementById("<%=UpdatePanel1.ClientID %>").scrollLeft = xPos;
               document.getElementById("<%=UpdatePanel1.ClientID %>").scrollTop = yPos;
           }
 </script>

For panel and for div and update panel..these all are fails completely, why because if child page is getting post back means the related master pages also post backed..but I don't know how to maintain the scroll position..

please Try to help me as soon as possible..

Thanks guys

Answers (3)