Custom NodeTemplate causes client side errors

2 posts, 0 answers
  1. Mike R
    Mike R avatar
    1 posts
    Member since:
    Dec 2009

    Posted 01 Dec 2009 Link to this post



    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

  2. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 02 Dec 2009 Link to this post

    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); 
                    } 
                } 
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top