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

RadTreeNode Custom Attributes

6 Answers 201 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vme
Top achievements
Rank 1
Vme asked on 24 Jul 2009, 01:11 PM
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>

6 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 27 Jul 2009, 01:55 PM
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.
0
Vme
Top achievements
Rank 1
answered on 27 Jul 2009, 02:00 PM
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!
0
Yana
Telerik team
answered on 29 Jul 2009, 11:52 AM
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.
0
luc bonenfant
Top achievements
Rank 1
answered on 01 Oct 2009, 04:49 PM
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.
0
luc bonenfant
Top achievements
Rank 1
answered on 02 Oct 2009, 07:17 PM
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();  
        }  
 
0
Yana
Telerik team
answered on 05 Oct 2009, 06:58 AM
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.
Tags
TreeView
Asked by
Vme
Top achievements
Rank 1
Answers by
Yana
Telerik team
Vme
Top achievements
Rank 1
luc bonenfant
Top achievements
Rank 1
Share this question
or