0

I am using a Tree View Hierarchy inside the UpdatePanel. The ASP.NET code is:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:TreeView ID="HierarchyTreeView" runat="server" meta:resourcekey="HierarchyTreeViewResource1" EnableViewState="true"></asp:TreeView>
    </ContentTemplate>
</asp:UpdatePanel>

and on code behind i am writing

protected override void OnInit(EventArgs e)
{
        base.OnInit(e);
        HierarchyTreeView.PathSeparator = CaseListPresenter.PathSeparator;
        HierarchyTreeView.TreeNodePopulate += new TreeNodeEventHandler(HierarchyTreeView_TreeNodePopulate);
        HierarchyTreeView.SelectedNodeChanged += delegate {
            Presenter.CancelChangeFlag(); 
            Presenter.SelectedNodeChanged(); 
            CheckPreview(); 
        };
}

If I am using TreeView outside the UpdatePanel my OnInit is working well. But, if I am using TreeView inside the UpdatePanel, it is not working properly. I want to maintain the scroll position of my tree view

Rocky
  • 4,454
  • 14
  • 64
  • 119

2 Answers2

0

TreeView is not fully supportive with update panel.

we can maintain the scroll position by using following script:

<script language="javascript" type="text/javascript">
         var IsPostBack = '<%=IsPostBack.ToString() %>';
         window.onload = function() {
             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("<%=Panel4.ClientID %>").scrollTop = strPos;
                 }
                 else {
                     document.cookie = "yPos=!~0~!";
                 }
             }
         }
         function SetDivPosition() {
             var intY = document.getElementById("<%=Panel4.ClientID %>").scrollTop;
             document.title = intY;
             document.cookie = "yPos=!~" + intY + "~!";
         }  

</script>

call the setDivPosition() on ur Panel4

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
Rocky
  • 4,454
  • 14
  • 64
  • 119
  • This script is working fine, but the whole browser scroll is not in control. if data is so long then it is first scrolling top then its coming to bottom (on the old position) – Rocky Jun 28 '11 at 04:58
0

Now finally i got the solution with this..

Maintain Panel Scroll Position On Partial Postback ASP.NET

Community
  • 1
  • 1
Rocky
  • 4,454
  • 14
  • 64
  • 119