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

RadTreeView Dynamic NodeTemplate

6 Answers 347 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Neel
Top achievements
Rank 1
Neel asked on 06 May 2010, 07:30 PM
Hello,

I have a RadTreeView in which i am dynamically adding nodes from classes that are inherited from RadTreeNode. Each class defines few different text fields, as well as a NodeTemplate (each class uses its own node template).

Everything seems to render fine, until a postback is fired. It seems that as soon as the page posts back, all my NodeTemplates become null. I have tried explicitly setting EnableViewState=true on my RadTreeView and all my nodes, and basically every object i am using.

Also depending on the number of child nodes I add (i haven't found a specific pattern to this), the page sometimes doesn't even postback at all, but just gives me ViewState Errors. In this situation if i remove the line where i define my NodeTemplate in each class, the error goes away. It all seems to boil down to my node templates not persisting on postback.

The problem seems to be similar to this: http://www.telerik.com/community/forums/aspnet/treeview/radtreeview-nodetemplate-navigateurl.aspx , but i am not using NavigateUrl. The only base properties that i am setting are Text, Value, NodeTemplate and EnableViewState.

I downloaded the latest trial version last week (DLL version 2010.1.415.35)
Any thoughts?

Thanks.





6 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 07 May 2010, 08:23 AM
Hello Neel,

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

Kind regards,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Neel
Top achievements
Rank 1
answered on 10 May 2010, 03:13 PM
Thanks Yana,

I have to say i'm a little disappointed that dynamic node templates aren't preserved in postbacks.

What would be the best place to re-apply these templates? I have tried in my page_load event and in the even that is triggering the Postback, but neither seems to apply the nodetemplate.

Thanks,

Neel
0
Nikolay Tsenkov
Telerik team
answered on 10 May 2010, 04:58 PM
Hi Neel,

You should apply the template in the OnInit() page server method. But first you have to create a class implementing the ITemplate interface. This class will represent your custom template.
Please read the already mentioned tutorial for templating at runtime:
 http://www.telerik.com/help/aspnet-ajax/tree_templatesruntime.html

Hope this will solve your problem!


Regards,
Nikolay Tsenkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Peter Blair
Top achievements
Rank 1
answered on 10 May 2010, 09:47 PM
Hi Yana,
Can multiple templates be applied in the OnInit() section.  I'm dynamically creating the nodes on the server side, but also want to apply different templates to the root nodes, versus the child nodes.  Is this possible?

What I'm looking to be able to do is create something similar to the templates used in this example, but dynamically on the server side: example

Thanks,
Peter
0
Yana
Telerik team
answered on 11 May 2010, 03:04 PM
Hello Peter,

Actually when the template is set in OnInit, it's set to the whole treeview for all the nodes. In your case you can set different templates for root and child nodes in Page_Load, I've prepared a simple page to demonstrate this approach, please download the attached file and give it a try.

Best wishes,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Peter Blair
Top achievements
Rank 1
answered on 12 May 2010, 05:26 PM
Thank you, Yana
Tags
TreeView
Asked by
Neel
Top achievements
Rank 1
Answers by
Yana
Telerik team
Neel
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Peter Blair
Top achievements
Rank 1
Share this question
or