Custom properties in descendants of RadTreeNode

7 posts, 1 answers
  1. Mark Kingsley
    Mark Kingsley avatar
    5 posts
    Member since:
    Jul 2009

    Posted 25 Jul 2009 Link to this post

    Hi,

    I'm implementing my own custom RadTreeNode via inheritance. It looks something like this

    public class TaggedTreeNode : RadTreeNode
    {
        
        public string[] Tags
        {
            get { return (string[])ViewState["tags"] ?? new string[] { }; }
            set { ViewState["tags"] = value; }
        }

    }

    While I can still utilize this new property on a server side during the rendering, when I place control inside RadAjaxPanel the first ajax postback empties the contents of the property. The thing is that nodes are expanded normally via OnNodeExpand, but when some other control on the RadAjaxPanel fires a postback the information from this property is lost.

    How can I create a custom property which will be persistent? It seems that no other property but described in RadTreeNode can be persisted at all during ajax postbacks.



    Thank you,
    Mark
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Jul 2009 Link to this post

    Hello Mark Kingsley,

    I tried to reproduce this problem in a simple web site to no avail. Could you please open a support ticket and send us a page which shows that behavior? I have also attached my test page.
    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Mark Kingsley
    Mark Kingsley avatar
    5 posts
    Member since:
    Jul 2009

    Posted 27 Jul 2009 Link to this post

    Hi Albert,

    Thanks for reply.

    The main discrepancy is that your code uses Page_Load to generate nodes, whilst my code uses OnNodeExpand event handler.

    protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e) 
        e.Node.Nodes.Add(new TaggedTreeNode { 
            Text = "Node N"
            Tags = new[] { "One""Two" } 
        }); 
     

    The tree view itself is placed inside a RadAjaxPanel alongside with drop down list which have AutoPostBack set to true.

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
     
    <asp:DropDownList 
        ID="DropDownList1" 
        runat="server" 
        AutoPostBack="true" 
        OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
    </asp:DropDownList> 
     
    <telerik:RadTreeView 
        ID="RadTreeView1" 
        runat="server"  
        OnNodeExpand="RadTreeView_NodeExpand" 
        EnableDragAndDrop="True" 
        EnableDragAndDropBetweenNodes="False"  
        MultipleSelect="True"
    </telerik:RadTreeView> 
     
    </telerik:RadAjaxPanel> 

    So, when I simply traverse through nodes inside DropDownList1_SelectedIndexChanged

    foreach (TaggedTreeNode node in EnumerateAllNodes(RadTreeView1)) 
        node.Tags.Length.ToString(); // This array is empty 

    Furthermore, the nodes of the tree cannot be cast to TaggedTreeNode during ajax postback -- they're all of type RadTreeNode regardless of how I create them (so I had to override RadTreeView.CreateItem method to return nodes of appropriate type. I even got as far as to reimplement RadTreeNode.LoadFromDictionary, but nothing seems to help -- the information injected in OnNodeExpand never reaches the form back on the server.)

    The same problem applies to RadTreeNode.Controls property populated during OnNodeExpand.

    I'll create a ticket if you will find my actions valid.

    Thank you.
  4. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Jul 2009 Link to this post

    Hi Mark Kingsley,

    I guess you are using ServerSideCallback load on demand mode. In this case this approach will not work as the RadTreeView persists only known properties from the client-side to the server side. I suggest you try custom attributes instead. The other solution is to use ServerSide expand mode and ajaxify it to avoid the postback.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Mark Kingsley
    Mark Kingsley avatar
    5 posts
    Member since:
    Jul 2009

    Posted 28 Jul 2009 Link to this post

    Thanks.

    Could you please specify what is exactly a custom attribute technique?
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Jul 2009 Link to this post

    Hello Mark Kingsley,

    You can check this help article and this online demo for more information on custom attributes.
    Greetings,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Mark Kingsley
    Mark Kingsley avatar
    5 posts
    Member since:
    Jul 2009

    Posted 30 Jul 2009 Link to this post

    Hi,

    I've decided to go with ServerSide loading for now.

    Thanks,
    Mark
Back to Top