Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
How do i maintain DIV scroll Position on Postback without using Update Panel.
 

Thanks and Regards
 
Deepak
Posted 16 Jun '11 - 0:50


4 solutions

Have a look at this article: JavaScript Access to Page Controls after Ajax Update (via Update Panel)[^]
 
UPDATE:
Sorry for not reading 'not update panel'
You can try,
1. Page.MaintainScrollPositionOnPostBack = true;
2. You can track the scroll position before the postback and then when the page is loading, on page load using javascript you can set back the scroll.
  Permalink  
Comments
Monjurul Habib - 16 Jun '11 - 18:41
he needs the solution without update panel.anyway nice link.
S Mewara - 16 Jun '11 - 23:38
My Bad. I read it as Update panel thing. :doh: Thanks Monjural for telling me that. Updated the answer to make some sense now. :)
Monjurul Habib - 17 Jun '11 - 4:14
my 5 for the advice.
S Mewara - 17 Jun '11 - 4:45
Thanks.
AshishChaudha - 5 Jan '13 - 6:28
my +5!
Sandeep Mewara - 5 Jan '13 - 11:40
Thanks.
Hello,
 
Firstly, I would suggest using:
 
Page.MaintainScrollPositionOnPostBack = true;
 
in your PageLoad event to maintain page position for your whole page.
 
Now, for the div question. I found a nice solution to your question here:
http://radio.javaranch.com/pascarello/2005/07/18/1121709316718.html[^]
 
I changed it a bit so to work with hiddenfield and not cookie. Below is the result.
 
<script type="text/javascript">
        window.onload = function () {
            var h = document.getElementById("<%=keep.ClientID%>");
            document.getElementById("divTest").scrollTop = h.value;
            alert(h.value);
        }
      function SetDivPosition(){
        var intY = document.getElementById("divTest").scrollTop;
        var h = document.getElementById("<%=keep.ClientID%>");
        h.value = intY;
      }
    </script>
 
Below is the starting tag of the div you want to maintain.
 
<div önscroll="SetDivPosition()" id="divTest">
</div>
 
Notes:
- "divTest" is the name of the div you wish to maintain
- "keep" is the name of the hidden field I used
 
Tested with IE 8, Firefox 4 and Chrome 12.
 
Hope it helps!
  Permalink  
Comments
SushantSundar - 10 May '12 - 5:51
Thanks a ton. Badly needed it.
var xPos, yPos;
       var prm = Sys.WebForms.PageRequestManager.getInstance();
       prm.add_beginRequest(BeginRequestHandler);
       prm.add_endRequest(EndRequestHandler);
 

       function BeginRequestHandler(sender, args) {
 

           yPos = $('#<%=divgvlocation.ClientID %>').scrollTop();
       }
       function EndRequestHandler(sender, args) {
 
           $('#<%=divgvlocation.ClientID %>').scrollTop(yPos);
       }
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 330
2 Arun Vasu 253
3 Zoltán Zörgő 194
4 CPallini 173
0 Sergey Alexandrovich Kryukov 10,105
1 OriginalGriff 7,739
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 2,999


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 6 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid