Click here to Skip to main content
14,331,142 members
Rate this:
Please Sign up or sign in to vote.
Not find any solution till Now.
Hi Experts,
I am facing a problem.I have a page. I want to apply Maintain scroll position on this page. I have used
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...

<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;

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <asp:Panel ID="Panel1" runat="server" Height="300">
        <----"my html table code here which have drop down,textbox,radiobutton,button etc controls"----->
and many othes functions.


Updated 10-Aug-14 21:53pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

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?
Rate this:
Please Sign up or sign in to vote.

Solution 2

Put this JavaScript code in your page.

<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");
                input.value = scrollY;
ErBhati 11-Aug-14 5:44am
not works for me. Scroll always go to the top.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Just remove Update panel from my code..and works fine for me.

Thanks to all for reply.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100