NodeTemplate on postback

3 posts, 0 answers
  1. Alexey
    Alexey avatar
    5 posts
    Member since:
    Jun 2011

    Posted 07 Mar 2012 Link to this post


    I have a RadTreeView and button on the page, RadTreeView is filled programmatically when click on the button. I use NodeTemplate for nodes but after postback template is not used. Could anybody help me?

    <telerik:RadScriptManager ID="ScriptManager" runat="server" EnableViewState="false"></telerik:RadScriptManager>
            <telerik:RadAjaxManager ID="AjaxManager" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                    <telerik:AjaxSetting AjaxControlID="rtvSearchResult" EventName="OnNodeClick">
                            <telerik:AjaxUpdatedControl ControlID="rtsObjInfo"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxSetting AjaxControlID="btnSearch">
                            <telerik:AjaxUpdatedControl ControlID="rtvSearchResult"></telerik:AjaxUpdatedControl>
                <ClientEvents OnResponseEnd="OnResponseEnd" />
    <telerik:RadTreeView ID="rtvSearchResult" OnNodeClick="rtvSearchResult_NodeClick"
                                                        OnClientMouseOver="onNodeOver" OnClientMouseOut="onNodeOut" runat="server" Height="100%">
    <asp:Button ID="btnSearch" OnClick="btnSearchClick" runat="server" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>

    public List<common.DOCUMENT_OBJECT_MAP> list;
            protected void Page_Load(object sender, EventArgs e)
                list = new List<common.DOCUMENT_OBJECT_MAP>();
                list.Add(new common.DOCUMENT_OBJECT_MAP() { ID = 1, NAME = "Obj1" });
                list.Add(new common.DOCUMENT_OBJECT_MAP() { ID = 2, NAME = "Obj2" });
                list.Add(new common.DOCUMENT_OBJECT_MAP() { ID = 3, NAME = "Obj3" });
    protected void btnSearchClick(object sender, EventArgs e)
                foreach (common.DOCUMENT_OBJECT_MAP obj in list)
                    RadTreeNode newNode = new RadTreeNode();
                    newNode.Text = obj.NAME;
                    newNode.ToolTip = obj.NAME;
                    newNode.Value = obj.ID.ToString();
                    newNode.DataItem = obj.ID_LAYER;
                    newNode.NodeTemplate = new TreeNodeTemplate(obj);
                    RadTreeNode parentNode = rtvSearchResult.FindNodeByValue(obj.ID_FOLDER.ToString());
                    if (parentNode != null)
                rtvSearchResult.Visible = true;
    public class TreeNodeTemplate : ITemplate
            private common.DOCUMENT_OBJECT_MAP _obj;
            public TreeNodeTemplate(common.DOCUMENT_OBJECT_MAP obj)
                _obj = obj;
            public void InstantiateIn(Control container)
                Label control = new Label();
                control.ID = "lbn_" + _obj._ID;
                control.ClientIDMode = ClientIDMode.Static;
                control.Text = _obj._NAME;
                Label lbButtons = new Label();
                lbButtons.Text = "<input type='button' value='1'/>";
                lbButtons.ID = "node_" + _obj.ID + "_cmd";
                lbButtons.ClientIDMode = ClientIDMode.Static;

  2. Plamen
    Plamen avatar
    2817 posts

    Posted 12 Mar 2012 Link to this post

    Hi Alexey,

    Dynamically added templates are not persistent and should be added on every postback. Please check this help article which demonstrates this approach. 

    You can also refer to this forum thread where a similar issue is discussed.

    Plamen Zdravkov
    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.
  3. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 23 Oct 2013 Link to this post

    Oopps!  Wrong  thread!
Back to Top