This is a migrated thread and some comments may be shown as answers.

[Solved] Tree Collapses after check node postback

3 Answers 172 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
rene
Top achievements
Rank 1
rene asked on 08 May 2008, 09:27 PM
After I check on a node and handle that on the code behind, the node that was checked collapses.

Please help!

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 09 May 2008, 12:25 PM
Hi rene,

I could not reproduce the problem with our online example on CheckBox Support. If you check a parent node on the right, a postback appear and the expanded state will be persisted after the postback.

What is different in your case?

Kind regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rene
Top achievements
Rank 1
answered on 09 May 2008, 02:43 PM
Hello Nick, thank you for your reply. Its a bit more complicated, I'll explain.

I am doing a custom control (Composite Control). One of the controls that I display in my custom control is a RadTreeView. The code is as follows:

namespace Altep.Web.Controls
{

        public class WebTree : CompositeControl, ITreeControl
        {
                protected RadTreeView _treeView;

                public WebTree()
                {
                    _treeView = new RadTreeView();
                }

                 ....

                protected override void CreateChildControls()
                {
                    _treeView.ID = TreeID + "_" + this.ID;
                    _treeView.CheckBoxes = true;
                    _treeView.AutoPostBackOnCheck = true;
                    _treeView.AfterClientCheck = "jsAfterCheck";
                    _treeView.NodeCheck += new RadTreeView.RadTreeViewEventHandler(NodeCheckEventHandler);

                    LoadTree(MyDataSource);

                    Controls.Add(_treeView);

                    base.CreateChildControls();
                }

                ....


                protected void NodeCheckEventHandler(object o, RadTreeNodeEventArgs e)
                {
                        //get all checked nodes from tree
                        ArrayList checkedNodeCollection = _treeView.CheckedNodes;

                        foreach(RadTreeNode checkedNode in checkedNodeCollection)
                        {
                                //synch with my model
                         }
                }

                ...

        }
}


On my javascript side, I have the following

function CheckAllChildren(nodes, checked)
{

        for(var i = 0; i < nodes.length; ++i){
            if(checked)  nodes[i].Check();
            else  nodes[i].UnCheck();

            if(nodes[i].Nodes.length > 0)
                CheckAllChildren(nodes[i].Nodes, checked);
        }

        return;
}


function  jsAfterCheck(node)
{

        CheckAllChildren(node.Nodes, node.Checked);

        return;

}


I have the problem of when the node is checked, I get the post back to my NodeCheckEventHandler method, but after exiting, the checked node collapses.

Second problem, the line

ArrayList checkedNodeCollection = _treeView.CheckedNodes;


returns one, even though in my GUI I have the parent and all of its children cheked.

BTW, when AutoPostBackOnCheck = false;

The checked node does not collapse.

Am I missing something?  Does rendering the control this way changes things?

Please help
0
Nikolay
Telerik team
answered on 12 May 2008, 11:06 AM
Hello rene,

I am afraid that there is not much I can say without first seeing your project files. Can you put together a small and running project and attach the files to a new support thread? We will test them locally and try to find a working solution for you.

Expecting your reply,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
rene
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
rene
Top achievements
Rank 1
Share this question
or