Friday, 14 October 2016

Preserve scroll position of DIV in UpdatePanel through Postback in asp.net







<script type="text/javascript">

    window.onload = function () {
        var div = document.getElementById("divid");
        var div_position = document.getElementById("div_position");
        var position = parseInt('<%=Request.Form["div_position"] %>');
        if (isNaN(position)) {
            position = 0;
        }
        div.scrollTop = position;
        div.onscroll = function () {
            div_position.value = div.scrollTop;
        };
    };

</script>

  <div id="divid" style="width:97%; overflow:auto; min-height: 430px; max-height: 430px;">
// Your Code
</div>
<input type="hidden" id="Hidden1" name="div_position" />

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...