简体   繁体   中英

tree view Hierarchy is not working properly in side the Update panel

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

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

Now finally i got the solution with this..

Maintain Panel Scroll Position On Partial Postback ASP.NET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM