RadTreeNode Custom Attributes

7 posts, 0 answers
  1. Vme
    Vme avatar
    18 posts
    Member since:
    Mar 2008

    Posted 24 Jul 2009 Link to this post

    Hello,

    I'm trying to create custom attributes on a Radtreenode that is being build with the property ServerSideCallback.  For some reason, when I create this node with node.Attributes.Add("key", "Value"), it keeps the attribute at first.  But once it posts back and I access the node via the RadTreeNodeEventArgs e.Node.  My attributes Count=0 and I have no keys available to access the value.  If I change the node to ServerSide, everything works fine, however, this isn't what I want.

    Any suggestions or thoughts would be great.


    --This is where i create the node.
    <code>
    foreach (var zone in x)
                 {
                     RadTreeNode zoneNode = new RadTreeNode();
                     zoneNode.Text = String.Format("Zone {0}", zone.ZoneName);
                     zoneNode.Value = zone.NSD_ZoneID.ToString();
                     zoneNode.Expanded = false;
                     zoneNode.ExpandMode = TreeNodeExpandMode.ServerSide;
                     zoneNode.Attributes.Add("type", "OnDemand");
                     zoneNode.PostBack = true;
                     zoneNode.Checkable = false;
                     node.Nodes.Add(zoneNode);
                 }
    </code>


    <code>
    //This is where the e.Node.Attributes.Count = 0;
    protected void DPTTreeView_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
            {
                 switch (e.Node.Attributes["type"])
                 {
    ...snip....
    }
    }
    </code>
  2. Yana
    Admin
    Yana avatar
    5025 posts

    Posted 27 Jul 2009 Link to this post

    Hi Kyle,

    I suggest you use ExpandMode="ServerSide" and put RadTreeView inside RadAjaxPanel in order to ajaxify it.

    Best wishes,
    Yana
    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. Vme
    Vme avatar
    18 posts
    Member since:
    Mar 2008

    Posted 27 Jul 2009 Link to this post

    I know that will work, I mentioned it in my post. However, that isn't what I want to do.  Why do custom attributes NOT WORK with ServerSideCallback?  Is this a bug?  Is this an intentional design?  Should I upgrade/downgrade to get this to work correctly?

    If it is a bug I would hope to see some official documentation so I can confirm.

    Thank you!
  4. Yana
    Admin
    Yana avatar
    5025 posts

    Posted 29 Jul 2009 Link to this post

    Hello Vme,

    Actually this is expected behavior, because when you add nodes with ServerSideCallBack ExpandMode you can only set their Text and Value properties (as the new nodes are added through asynchronous callback, they're not serialized ). I've attached a simple page to show you a possible work-around, please download it and give it a try.

    Kind regards,
    Yana
    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. luc bonenfant
    luc bonenfant avatar
    53 posts
    Member since:
    Sep 2007

    Posted 01 Oct 2009 Link to this post

    Hello,

    I'm using custom attributes too for node expand and I tested your zip file ; it's working great.
    But I tried to adapt the code for my specification and it doesn't work :
    VB:
     
            Public Sub RadTreeView1_NodeExpand(ByVal sender As ObjectByVal e As RadTreeNodeEventArgs)  
     
                e.Node.Attributes.Add("type""OnDemand")  
     
            End Sub 
    Javascript:
            function nodePopulated(sender, args) {  
                sender.trackChanges();  
                var node = args.get_node();  
                node.get_attributes().setAttribute("type", node.get_textElement().attributes["type"].value);  
                sender.commitChanges();  
            }  
     

    Perhaps, the current node is not recalculate during ajax, because it already exists on the page...

    It's very important that I retrieve the node attributes when I expand it, have you got a solution please ?
    PS1 : I can't load the attributes for each subnode (your solution) because it's not efficient in my case ; it's better for me to get node attributes directly when node is expanded
    PS2 : ExpandMode = ServerSide is not a good solution because my ajax render is big for each expand depth.

    Thank you for help.
  6. luc bonenfant
    luc bonenfant avatar
    53 posts
    Member since:
    Sep 2007

    Posted 02 Oct 2009 Link to this post

    Finally, i'm using your code to arrive at my aim like this : (not great but functional...)
    VB :
            Public Sub RadTreeView1_NodeClick(ByVal sender As ObjectByVal e As RadTreeNodeEventArgs)  
     
                Dim attr As String = e.Node.Attributes("type")  
     
            End Sub 
     
            Public Sub RadTreeView1_NodeExpand(ByVal sender As ObjectByVal e As RadTreeNodeEventArgs)  
     
                Dim zoneNode As New RadTreeNode()  
                zoneNode.Text = "Tmp" 
                zoneNode.Attributes.Add("type""OnDemand")  
                e.Node.Nodes.Insert(0, zoneNode)  
     
            End Sub 
    Javascript :
            function nodePopulated(sender, args) {  
                var parentNode = args.get_node();  
                var childNode = args.get_node().get_nodes().getNode(0);  
                sender.trackChanges();  
                if (childNode.get_textElement().attributes["type"])  
                    parentNode.get_attributes().setAttribute("type", childNode.get_textElement().attributes["type"].value);  
                parentNode.get_nodes().remove(childNode);  
                sender.commitChanges();  
            }  
     
  7. Yana
    Admin
    Yana avatar
    5025 posts

    Posted 05 Oct 2009 Link to this post

    Hello Luc,

    I'm glad you could find a solution.

    Best wishes,
    Yana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top