Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I work in Asp.net and use TreeView control.

protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes.Count > 0 && e.Node.Checked)
            {
                foreach (TreeNode childnode in e.Node.ChildNodes)
                {
                    childnode.Checked = true;
                }
            }
            else if (e.Node.ChildNodes.Count > 0 && !e.Node.Checked)
            {
                foreach (TreeNode childnode in e.Node.ChildNodes)
                {
                    childnode.Checked = false;
                }
            }
            else if (e.Node.ChildNodes.Count == 0 && e.Node.Checked)
            {
                e.Node.Parent.Checked = true;
            }
            else if (e.Node.ChildNodes.Count == 0 && Count_checkedChilds(e.Node.Parent) == 0)
            {
                e.Node.Parent.Checked = false;
            }
        }

        protected int Count_checkedChilds(TreeNode node)
        {
            int k = 0;
            foreach (TreeNode childnode in node.ChildNodes)
            {
                if (childnode.Checked == true)
                {
                    k++;
                }
            }
            return k;
        }



And I use below code in front:

<pre><div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
          
        <asp:TreeView ID="TreeView1" runat="server" Width="189px" OnTreeNodeCheckChanged="TreeView1_TreeNodeCheckChanged">
            

        </asp:TreeView>
        
    </div>
    <script type="text/javascript">
        var btn = document.getElementById("Button1");
        function postBackByObject() {
            var o = window.event.srcElement;
            if (o.tagName == "INPUT" && o.type == "checkbox") {
                __doPostBack("", "");
                
            }
        }
    </script>


What I have tried:

When I click checkboxes PostBack() runs.But my treeview is on popup page and When I click checkbox my popup page disappeared.How can I fix this problem? Please help me immediately..
Posted
Updated 7-Feb-19 0:59am
v4
Comments
F-ES Sitecore 7-Feb-19 7:24am    
If you don't want the page refreshing you need to put the treeview in an UpdatePanel. Not sure if the javascript you have to trigger the postback will work with items in an updatepanel, if not you might need to find a different way of triggering the postback, but that's basically the solution you need to move towards.
Member 14141512 8-Feb-19 5:49am    
I use PostBack function for treeview control which I write it my question.When I use updatepanel Should I continue to use PstBack function??
Member 14141512 8-Feb-19 5:50am    
because without PostBack function treeview checkchange event doesn't work

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