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

Custom properties in descendants of RadTreeNode

6 Answers 179 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mark Kingsley
Top achievements
Rank 1
Mark Kingsley asked on 25 Jul 2009, 04:27 PM
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

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 Jul 2009, 07:26 AM
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.
0
Mark Kingsley
Top achievements
Rank 1
answered on 27 Jul 2009, 09:48 AM
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.
0
Accepted
Atanas Korchev
Telerik team
answered on 27 Jul 2009, 01:42 PM
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.
0
Mark Kingsley
Top achievements
Rank 1
answered on 28 Jul 2009, 02:09 PM
Thanks.

Could you please specify what is exactly a custom attribute technique?
0
Atanas Korchev
Telerik team
answered on 28 Jul 2009, 02:49 PM
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.
0
Mark Kingsley
Top achievements
Rank 1
answered on 30 Jul 2009, 07:23 AM
Hi,

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

Thanks,
Mark
Tags
TreeView
Asked by
Mark Kingsley
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Mark Kingsley
Top achievements
Rank 1
Share this question
or