Remember div scroll position using javascript and ASP.Net


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <script language="javascript">
  2. //remember the scroll position for the div
  3. function setScrollValue() {
  4. var divObj = $get('<%= divcontent.ClientID %>');
  5. var objHid = $get('<%= HiddenField1.ClientID %>');
  6. if (objHid) objHid.value = divObj.scrollTop;
  7. }
  8. function pageLoad() {
  9. var divObj = $get('<%= divcontent.ClientID %>');
  10. var objHid = $get('<%= HiddenField1.ClientID %>');
  11. if (divObj) divObj.scrollTop = objHid.value;
  12. }
  13. </script>
  14.  
  15. <asp:HiddenField ID="HiddenField1" runat="server" />
  16.  
  17. <div style="height:150px;overflow:scroll" id="divcontent" runat="server" onscroll="javascript:setScrollValue();"></div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.