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

Root nodes' text and image invisible after postback

7 Answers 74 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 25 Nov 2011, 12:46 PM
Hi,

I have a tree which is populated by LoadOnDemand (wcf). The root nodes are created server-side when the tree is initialized (initalize is only called once - when the page is not in PostBack).
After a postback, the root nodes don't have a text and an icon anymore. But the child nodes are all ok.

In the screenshot there are several RadDocks. But meanwhile I tested some scenarios and I can tell you that it always happens when
the tree is in an UpdatePanel.

If I add the tree directly to the page, everything is fine after a postback. If I add the tree to an UpdatePanel, the described problem occurs.

In the screenshot the RadDocks are recreated after a postback (and therefor no Initialize is called). Just the left one is the newly created tree which is also initialized.

7 Answers, 1 is accepted

Sort by
0
JP
Top achievements
Rank 1
answered on 29 Nov 2011, 02:54 PM
I think I know why the text and the icon disappear for nodes on the first level: 
The server-side generated nodes aren't added to the TreeView's clientstate. All nodes which are loaded on demand are added to the clientstate but the server-side generated nodes aren't. How can I make sure they are added to the clientside or is there any other solution for my problem?
0
Plamen
Telerik team
answered on 30 Nov 2011, 12:53 PM
Hello Jp,

I tried to reproduce the issue but with no success. So I will need some more information about your project in order to help you.

Would you please explain what is the difference between the way Load on demand (wcf) performed in our demo and in your case and how do you add these root nodes? 

Could you also explain the reason you are using the Update panel since the trees expand with web service?

Regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
JP
Top achievements
Rank 1
answered on 01 Dec 2011, 09:22 AM
Hi,

I added the tree to a RadWindow which is dynamically created. Thats where the UpdatePanel comes from. But I also tested it without the RadWindow and added the Tree directly to the page in an UpdatePanel (also tested with a RadAjaxPanel) and also in this cases the root nodes disappear.

This is the code where the nodes are created. The first method is for the root nodes, the second method is called by the webservice:

internal RadTreeNode ConvertToRadTreeNode()
      {
         RadTreeNode node = new RadTreeNode();
         node.Text = string.IsNullOrEmpty(Text) ? Designation + "(" + Label + ")" : Text;
         node.Attributes["InternalId"] = InternalId;
         node.Attributes["EntityType"] = EntityType;
         foreach (KeyValuePair<string, string> additionalKeyValue in AdditionalKeyValues)
         {
            node.Attributes["ValueProperty:" + additionalKeyValue.Key] = additionalKeyValue.Value;
         }
         node.ExpandMode = TreeNodeExpandMode.WebService;
         node.ImageUrl = ImageUrl;
         node.ToolTip = ToolTip;
         return node;
      }
 
      internal RadTreeNodeData ConvertToRadTreeNodeData()
      {
         RadTreeNodeData node = new RadTreeNodeData();
         node.Text = string.IsNullOrEmpty(Text) ? Designation + "(" + Label + ")" : Text;
         node.Attributes["InternalId"] = InternalId;
         node.Attributes["EntityType"] = EntityType;
         foreach (KeyValuePair<string, string> additionalKeyValue in AdditionalKeyValues)
         {
            node.Attributes["ValueProperty:" + additionalKeyValue.Key] = additionalKeyValue.Value;
         }
         node.ExpandMode = TreeNodeExpandMode.WebService;
         node.ImageUrl = ImageUrl;
         node.Attributes["ToolTip"] = ToolTip;
         return node;
      }

The root nodes are only added if the Page is not in Postback. The method is called only when the page is loaded the first time:

public void Initialize()
      {
         EnsureChildControls();
         m_radTreeView.Nodes.Clear();
         List<FmHierarchyAjaxTreeItem> items = _LoadChildren(string.Empty, null, m_configuration);
         items.ForEach(item => m_radTreeView.Nodes.Add(item.ConvertToRadTreeNode()));
      }

If I don't use any UpdatePanel, the root nodes don't disappear...


0
Nikolay Tsenkov
Telerik team
answered on 06 Dec 2011, 12:25 PM
Hello Jp,

Please, open a support ticket and send us a simple runnable project reproducing the issue.

I hope the problem is resolved soon.

Regards,
Nikolay Tsenkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
JP
Top achievements
Rank 1
answered on 06 Dec 2011, 03:41 PM
Hi,

I was able to reproduce this issue with another sample application and submitted this as a ticket.

Thanks!
0
Accepted
Nikolay Tsenkov
Telerik team
answered on 08 Dec 2011, 09:56 AM
Hello Jp,

We have successfully resolved the issue in the support thread.

For everyone that might stumble upon this, the problem was the following:
 - the TreeView was populated before added to the page. This caused a viewstate tracking problem for the nodes, because their properties (Text, ExpandMode etc.), were set, before the nodes are part of the page's Control Tree.

Solution:
 - First add the TreeView to the page, then create the nodes, set their properties and finally add them to the TreeView.

Regards,
Nikolay Tsenkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
JP
Top achievements
Rank 1
answered on 08 Dec 2011, 11:26 AM
Thanks!
I call the method which adds the root nodes now after the control was added to the page and it works fine!
Tags
TreeView
Asked by
JP
Top achievements
Rank 1
Answers by
JP
Top achievements
Rank 1
Plamen
Telerik team
Nikolay Tsenkov
Telerik team
Share this question
or