Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have a requirement based on word document load in a div along with load separated (Table of contents) in another div. Here Table of contents are binded to Treeview, then we click treeview node the div scroll top. Actual action i want wherever we click treeview node the scroll maintain there position.

please help

What I have tried:

My Code:
<div class="row">
        <div class="col-lg-3 sidenav">    
            <asp:linkbutton id="lbhome" visible="false" runat="server" text="Home" onclick="lbhome_Click">
           <asp:treeview id="TVcontents" runat="server" onselectednodechanged="TVcontents_SelectedNodeChanged" font-size="Small">
                         
           </div>
        <div class="col-lg-9 contentnav">          
             <asp:label id="marketname" runat="server" font-bold="true" font-size="XX-Large">
            <div id="pagecontent" class="pagestyle" style="height: 475px"></div>             
        </div>
    </div>

I tried MaintainScrollPositionOnPostback=true,
I tried
$(function () {
//recover the scroll postion
$("#tvDiv").scrollTop($("#HiddenScrollTop").val());
$("#tvDiv").scrollLeft($("#HiddenScrollLeft").val());
})
$(function () {
//save the scroll position
$("#tvDiv").scroll(function () {
$("#HiddenScrollLeft").val($(this).scrollLeft());
$("#HiddenScrollTop").val($(this).scrollTop());
});
})

and so many but they didn't work
Posted
Updated 15-May-19 17:28pm
v3

1 solution

var IsPostBack= '<%=IsPostBack.ToString() %>';
        window.onload = function () {
            debugger;
            var strCook = document.cookie;
            if(strCook.indexOf("!~")!=0){
                var intS = strCook.indexOf("!~");
                var intE = strCook.indexOf("~!");
                var strPos = strCook.substring(intS+2,intE);
                if (IsPostBack=='True')
                {
                    document.getElementById("<%=pnlTree.ClientID %>").scrollTop = strPos;
                }
                else
                {
                    document.cookie = "yPos=!~0~!";
                }
            }
        }
        function SetDivPosition(){
            var intY = document.getElementById("<%=pnlTree.ClientID %>").scrollTop;
            document.title = intY;
            document.cookie = "yPos=!~" + intY + "~!";
        }

<asp:panel id="pnlTree" runat="server" height="462px" width="307px" scrollbars="Auto" onscroll="SetDivPosition()">
            <asp:treeview id="TVcontents" runat="server" onselectednodechanged="TVcontents_SelectedNodeChanged" font-size="Small">
            </asp:treeview>         
            </asp:panel>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900