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

findNodeByValue returns null after refreshing parent node

2 Answers 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Inge
Top achievements
Rank 1
Inge asked on 01 Mar 2012, 02:16 PM
Hi everyone,

I am having a problem refreshing a node after saving changes on the server side.  A summary:

I have an ASP.NET Ajax RadTreeView within an UpdatePanel.  A user selects a node and clicks an Edit button.  This opens a jQuery dialog in which node data can be changed, such as the description (not the value!).  After clicking the Save button in the dialog, a piece of JavaScript triggers a button, which has been registered for AsyncPostBack.  On the server side, the node data is saved, and execution returns to a JavaScript method on the page.  I then want to refresh the node that has been edited, in order to display, for instance, the new description for the node.  I might be going about this the wrong way, but I thought I would be able to accomplish this by refreshing the node's parent, and then re-selecting the node itself.  Everything works, accept re-selecting the node that had been edited. 

I write the following code:

var tree = FindTree();
var currentNodeValue = tree.get_selectedNode().get_value();
RefreshParentNode();
var currentNode = tree.findNodeByValue(currentNodeValue);
// TODO: why is this node not found?!?
// For now, after update, the parent is selected because the child node is not found, even though it is there...
if (currentNode) {
    currentNode.select();
}

The RefreshParentNode function simply finds the parent node of the selected node, and then refreshes it using the following code:

function RefreshNode(node) {
    if (node) {
        node.collapse();
        node.get_treeView().trackChanges();
        node.get_nodes().clear();
        node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.WebService);
        node.get_treeView().commitChanges();
        node.expand();
    }
}

All nodes are now displayed correctly, including the updated node with its new description.  However, as the comments in the code fragment at the top show, the findNodeByValue function fails to find the node that had been edited, so I can't re-select it.

So, I basically, have two questions:

1) Is there an easier way to get the edited node to display its new description?
2) If not: why is the node not found by findNodeByValue after refreshing the parent, and how can I fix this?

By the way, in case this is not clear from the code fragments above: I am using a LoadOnDemand scenario.  Root nodes are loaded immediately, child nodes are loaded using a webservice.

UPDATE: Yes, the FindTree method uses $find and not $get.  The tree reference is not the problem...

Regards,
Inge

2 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 05 Mar 2012, 09:51 AM
Hi Inge,

The problem in your case might be caused by a timing issue, since you are trying to find the edited node  immediately after you have cleared the nodes of its parent and a new request for nodes has been made. Please try to preselect your edited item once the OnClientNodePopulated event is fired. This way you will ensure that the request for nodes is finished.

Kind regards,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Inge
Top achievements
Rank 1
answered on 05 Mar 2012, 11:06 AM
Thank you!  That was exactly what I was looking for.
Tags
TreeView
Asked by
Inge
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Inge
Top achievements
Rank 1
Share this question
or