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

NodeTemplate on postback

2 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alexey
Top achievements
Rank 1
Alexey asked on 07 Mar 2012, 01:44 PM
Hello,

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?

ASPX
<telerik:RadScriptManager ID="ScriptManager" runat="server" EnableViewState="false"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="AjaxManager" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rtvSearchResult" EventName="OnNodeClick">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rtsObjInfo"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnSearch">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rtvSearchResult"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
            <ClientEvents OnResponseEnd="OnResponseEnd" />
        </telerik:RadAjaxManager>
<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>


CodeBehind
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)
        {
            rtvSearchResult.Nodes.Clear();
             
            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)
                {
                    parentNode.Nodes.Add(newNode);
                }
                else
                {
                    rtvSearchResult.Nodes.Add(newNode);
                }
            }
            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;
            container.Controls.Add(control);
             
            Label lbButtons = new Label();
            lbButtons.Text = "<input type='button' value='1'/>";
            lbButtons.ID = "node_" + _obj.ID + "_cmd";
            lbButtons.ClientIDMode = ClientIDMode.Static;
            container.Controls.Add(lbButtons);
        }
    }

Thanks!

2 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 12 Mar 2012, 09:48 AM
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.

Greetings,
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.
0
nfigueroa
Top achievements
Rank 1
answered on 23 Oct 2013, 01:54 PM
Oopps!  Wrong  thread!
Tags
TreeView
Asked by
Alexey
Top achievements
Rank 1
Answers by
Plamen
Telerik team
nfigueroa
Top achievements
Rank 1
Share this question
or