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

[Solved] radtreenodes added but missing template

2 Answers 166 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
nick b-w
Top achievements
Rank 1
nick b-w asked on 26 Nov 2009, 06:37 AM
Hi all,

I have added node templates using the following code:

<NodeTemplate> 
                <img alt="node type" src="/Media/help_16.png" class='nodeClass<%# Eval("NodeTypeId") %>' /> 
                <asp:Label ID="text" runat="server"><%# Eval("Title") %></asp:Label> 
            </NodeTemplate> 

this works fine on all of my nodes when they are loaded remotely, however when i want to add a new node on the client-side using something like this:

currentNode.get_nodes().add(newNode); 

it will add the node, but it will ignore the template.

is this a bug, or am i missing something?

currentNode doesn't have access to the controls collection that you have when you add a node server side, nor can i find a way to add a template when adding a node to the currentNode.get_nodes() array in javascript.

any thoughts would be greatly appreciated.

thanks

Nick

2 Answers, 1 is accepted

Sort by
0
Per
Top achievements
Rank 1
answered on 02 Dec 2009, 02:40 PM
I have almost exactly the same problem. When I'm not using a node template this works perfect.
 
                <NodeTemplate> 
                    <telerik:RadToolTip ID="rttImg" runat="server" TargetControlID="imgNode" Position="TopRight" Animation="None"  HideEvent="LeaveTargetAndToolTip" /> 
                    <asp:Label ID="lblNodText" runat="server" Text='<%# Eval("namn") %>'></asp:Label><asp:Image ID="imgNode" runat="server" Visible="false" ImageUrl="../images/treeview/comment-left.png" style="margin-left:5px;" /> 
                </NodeTemplate> 

I have a Java script that makes the added node goto edit mode (for a name change), this also works ok.

function pageLoad(){  
var tree = $find(\"" + rtv_fys.ClientID + "\");  
var node = tree.get_selectedNode();  
node.startEdit();} 

As soon as name is changed you can see the node but no with no content. Is this caused by the fact that the new node is not bound to the datasource?
0
nick b-w
Top achievements
Rank 1
answered on 02 Dec 2009, 09:49 PM
sorry i should have written back sooner, but there is no way to add a node client side using a template, i found that in the documentation, this is inside the how to -> client side At the moment, it is not possible to assign a real template to a client-side node. Templates are rendered on the server side, hence the limitation. If you need some additional HTML (no server controls) you can "inject" it in the node's HTML. 

The solution i have is that i use is that i save a new node to the database using a webmethod, if it saves okay then i do a refresh on the parent node, i have the node expand mode set to: .ExpandMode = TreeNodeExpandMode.ServerSideCallBack this will then refresh the nodes from the database, the main problem with this approach is if a node has already been expanded, as once it has been expanded its expandmode goes to client side, so after successful add of the node, in the client side code i do this:

node.collapse(); 
        node.get_treeView().trackChanges(); 
        node.get_nodes().clear(); 
        node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.ServerSideCallBack); 
        node.get_treeView().commitChanges(); 
        node.expand(); 

this will switch it back to server side and also expand it. this will then use your template.
Tags
TreeView
Asked by
nick b-w
Top achievements
Rank 1
Answers by
Per
Top achievements
Rank 1
nick b-w
Top achievements
Rank 1
Share this question
or