Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Not find any solution till Now.
Hi Experts,
I am facing a problem.I have a asp.net page. I want to apply Maintain scroll position on this page. I have used
C#
MaintainScrollPositionOnPostback="true" 
by all tree types (on cs,aspx and in web config) and many other Javascript functions (after googled).but no java script function works for me. If anyone have an Idea about how I Maintain my Scroll Position on my page .Please help Me. I googled a lots but not found any solution till now ..for example I used functions of java scripts like...

C#
<form id="form1"  runat="server">
  <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />
   <script type="text/javascript">    
      var xPos, yPos;
      var prm = Sys.WebForms.PageRequestManager.getInstance();

      function BeginRequestHandler(sender, args) {
        if ($get('<%=Panel1.ClientID%>') != null) {         
          xPos = $get('<%=Panel1.ClientID%>').scrollLeft;
          yPos = $get('<%=Panel1.ClientID%>').scrollTop;
        }
     }

     function EndRequestHandler(sender, args) {
         if ($get('<%=Panel1.ClientID%>') != null) {       
           $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="300">
        <----"my html table code here which have drop down,textbox,radiobutton,button etc controls"----->
     </asp:Panel>
   </ContentTemplate>
 </asp:UpdatePanel>
and many othes functions.

Thanks

</form>
Posted
Updated 10-Aug-14 21:53pm
v5

 
Share this answer
 
Comments
ErBhati 17-Jul-14 8:05am    
I have already Used this but not works for me..Thanks for reply
pradiprenushe 17-Jul-14 8:30am    
Which browser?
pradiprenushe 17-Jul-14 8:34am    
Run code on IE & debug.
ErBhati 17-Jul-14 8:46am    
Chrome and mozilla...
pradiprenushe 17-Jul-14 8:53am    
Demo works on both browser can you provide your design code?
Put this JavaScript code in your page.

C#
<script type="text/javascript">
        //This is to maintain scroll position after postback
        window.onload = function () {
            var scrollY = parseInt('<%=Request.Form["scrollY"] %>');
            if (!isNaN(scrollY)) {
                window.scrollTo(0, scrollY);
            }
        };
        window.onscroll = function () {
            var scrollY = document.body.scrollTop;
            if (scrollY == 0) {
                if (window.pageYOffset) {
                    scrollY = window.pageYOffset;
                }
                else {
                    scrollY = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
                }
            }
            if (scrollY > 0) {
                var input = document.getElementById("scrollY");
                if (input == null) {
                    input = document.createElement("input");
                    input.setAttribute("type", "hidden");
                    input.setAttribute("id", "scrollY");
                    input.setAttribute("name", "scrollY");
                    document.forms[0].appendChild(input);
                }
                input.value = scrollY;
            }
        };
    </script>
 
Share this answer
 
Comments
ErBhati 11-Aug-14 5:44am    
not works for me. Scroll always go to the top.
Just remove Update panel from my code..and works fine for me.

Thanks to all for reply.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900