Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  127] [ 1]  / answers: 1 / hits: 28556  / 15 Years ago, sun, july 26, 2009, 12:00:00

I have a div as such:



<div style=overflow-y: scroll; height: 260px>


I contains a few hundred records and allows me to select an item to populate a formview control below it.



The problem is that when the page posts-back, the scroller position goes back to the top of the div. I want to try and maintain its position so that the selected record is still visible.



Any ideas?


More From » asp.net

 Answers
30

Place something like:



 <asp:HiddenField id=hdnScrollPos runat=server/> in your aspx.


Then, some javascript like:



var hdnScroll = document.getElementById(<%=hdnScrollPos.ClientID%>);
var bigDiv = document.getElementById('bigDiv');
bigDiv.onscroll = function() {
hdnScroll.value = bigDiv.scrollTop;
}

window.onload = function () {
bigDiv.scrollTop = hdnScroll.value;
}

[#99057] Tuesday, July 21, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;