RadTreeView Dynamic NodeTemplate

7 posts, 0 answers
  1. Neel
    Neel avatar
    4 posts
    Member since:
    Nov 2008

    Posted 06 May 2010 Link to this post

    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.





  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 07 May 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Neel
    Neel avatar
    4 posts
    Member since:
    Nov 2008

    Posted 10 May 2010 Link to this post

    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
  5. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 10 May 2010 Link to this post

    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.
  6. Peter Blair
    Peter Blair avatar
    3 posts
    Member since:
    Mar 2010

    Posted 10 May 2010 Link to this post

    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
  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 11 May 2010 Link to this post

    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.
  8. Peter Blair
    Peter Blair avatar
    3 posts
    Member since:
    Mar 2010

    Posted 12 May 2010 Link to this post

    Thank you, Yana
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017