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

Custom NodeTemplate causes client side errors

1 Answer 72 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mike R
Top achievements
Rank 1
Mike R asked on 01 Dec 2009, 06:41 AM



Hi,

I am wondering if anyone can offer any suggestions to resolve an problem I am having.

What I am trying to do: Programmatically create the equivalent of the NodeTemplate (as follows)

<telerik:RadTreeView ...

<Nodes>

<telerik:RadTreeNode>

<NodeTemplate>

some html in here....

</NodeTemplate>

</telerik:RadTreeNode>

</Nodes>


This is an example of the server side code which programmatically adds the nodes to the tree and uses a custom NodeTemplate RadTreeNodeTemplate (see below)

public class RadTreeNodeTemplate : ITemplate

{

private string content;



public RadTreeNodeTemplate(string text)

{

content = text;

}



#region ITemplate Members



public void InstantiateIn(Control container)

{

HtmlGenericControl nodeDiv = new HtmlGenericControl("div");

nodeDiv.Visible = true;

nodeDiv.InnerHtml = content;

nodeDiv.EnableViewState = true;

container.Controls.Add(nodeDiv);

}



#endregion

}

}

Tree building code:

....

RadTreeNode node = new RadTreeNode();

node.Expanded = true;

node.NodeTemplate = new RadTreeNodeTemplate(question.LibraryQuestion.ShortDescription);

node.Value = question.Id.ToString();

parentNode.Nodes.Add(node);

....

The problem is with the programmatically generated nodes cause client-side errors when you mouse over them when they have html content.

a.RadTreeNode.prototype={set_element:function(c){this._element=c;

this._element._item=this;


I figure the html rendered isn’t quite correct... What should I have my RadTreeNodeTemplate (custom ITemplate)

Any help would be greatly appreciated.

Cheers Michael

1 Answer, 1 is accepted

Sort by
0
Roland
Top achievements
Rank 1
answered on 02 Dec 2009, 03:22 PM
Hello,

I think you are right that HTML is not quite correct.

I am using similar scenario, which renders perfectly:

 public void InstantiateIn(Control container) 
            { 
 
                var node = (RadTreeNode)container; 
                var lblNodeText = new Label(); 
                lblNodeText.Text = node.Text; 
 
                container.Controls.Add(lblNodeText); 
 
                var inheritedText = node.Attributes["InheritedFrom"]; 
                var br = new HtmlGenericControl("br"); 
                var lblInheritedFrom = new Label(); 
                lblInheritedFrom.Font.Italic = true
                lblInheritedFrom.Text = inheritedText; 
 
                if (!string.IsNullOrEmpty(inheritedText)) 
                { 
                    container.Controls.Add(br); 
                    container.Controls.Add(lblInheritedFrom); 
                } 
            } 
Tags
TreeView
Asked by
Mike R
Top achievements
Rank 1
Answers by
Roland
Top achievements
Rank 1
Share this question
or