Return to Snippet

Revision: 29890
at August 5, 2010 01:01 by lance


Updated Code
<script language="javascript">
//remember the scroll position for the div
    function setScrollValue() {
        var divObj = $get('<%= divcontent.ClientID %>');
        var objHid = $get('<%= HiddenField1.ClientID %>');
        if (objHid) objHid.value = divObj.scrollTop;
    }
    function pageLoad() {
        var divObj = $get('<%= divcontent.ClientID %>');
        var objHid = $get('<%= HiddenField1.ClientID %>');
        if (divObj) divObj.scrollTop = objHid.value;
    }
 </script>

 <asp:HiddenField ID="HiddenField1" runat="server" />

            <div style="height:150px;overflow:scroll" id="divcontent" runat="server" onscroll="javascript:setScrollValue();"></div>

Revision: 29889
at August 5, 2010 00:57 by lance


Initial Code
<script language="javascript">
//remember the scroll position for the div
    function setScrollValue() {
        var divObj = $get('<%= divcontent.ClientID %>');
        var objHid = $get('<%= HiddenField1.ClientID %>');
        if (objHid) objHid.value = divObj.scrollTop;
    }
    function pageLoad() {
        var divObj = $get('<%= divcontent.ClientID %>');
        var objHid = $get('<%= HiddenField1.ClientID %>');
        if (divObj) divObj.scrollTop = objHid.value;
    }
 </script>

            <div style="height:150px;overflow:scroll" id="divcontent" runat="server" onscroll="javascript:setScrollValue();"></div>

Initial URL

                                

Initial Description

                                

Initial Title
Remember div scroll position using javascript and ASP.Net

Initial Tags

                                

Initial Language
JavaScript