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

    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. Plamen
    Admin
    Plamen avatar
    2731 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.

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 23 Oct 2013 Link to this post

    Oopps!  Wrong  thread!
Back to Top