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

ExpandMode: ServerSide vs. ServerSideCallback

3 Answers 141 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 02 May 2010, 12:53 AM
I've successfully populated your Treeview using this statement for every node:
  node.ExpandMode = TreeNodeExpandMode.ServerSide;
For each node I'd also added an "id" attribute with some special data in it.

Configured this way, everything works fine.

But now I've started investigating using this statement instead for every node:
  node.ExpandMode = TreeNodeExpandMode.ServerSideCallback;

After doing this I noticed that when a node is click, the "id" attribute appears not to exist.  In fact, in Debug mode I detected that the attribute count for each node was 0.

Any idea why?

Robert



3 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 03 May 2010, 07:07 AM
Hi Robert,

The difference between ServerSide and ServerSideCallback is:

ServerSide: This setting triggers a post back to fire the NodeExpand event. See the Server-Side Load On Demand topic for an example of using this setting.

ServerSideCallback: This value triggers an asynchronous callback that fires the NodeExpand event. See the Client-Side Load On Demand topic for an example of using this setting.

If you want to use custom attributes and to store a special data in them - don't use a known names of attributes for that. The reason in your case concrete is that ID attribute is used to reference the control in the code-behind.

Anyway I made a test project to check your scenario:

1.protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
2.   {
3.       RadTreeNode node = e.Node as RadTreeNode;
4.       string attribute = e.Node.Attributes["id"];
5.   }

If you set a breakpoint on row 4 - you'll see that the attribute is keeped.

1.<telerik:RadTreeNode id="SomeSpecialData" runat="server" ExpandMode="ServerSideCallBack" Text="Test">
2.               </telerik:RadTreeNode>

Find the full code in the attached .zip file.

Please let me know if I got your question.

Regards,
Veronica Milcheva
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
Robert
Top achievements
Rank 1
answered on 04 May 2010, 12:06 AM
Veronica,

Thank you for your help.  I'd like to give back to the Telerik developers community if I may . . .

In my case I've been testing out your treeview to use it as the main navigation tool for accessing a bunch of related data.  To keep track of the last selected RadTreeNode I've introduced a modular level property called "PreviousNodeID".  Originally I just generated a GUID and stored it in a node attribute called "id".  That worked well ... when I was using the ExpandMode property set to "ServerSide".

My recent testing has revealed "ServerSideCallBack" to be much faster (and understandably why!).  In trying to switch over everything to this faster ExpandMode setting I discovered that the "id" attribute was not appearing.  So then I got to wondering, why don't I just use each node's "UniqueID" value instead, storing the the last one into "PreviousNodeID"?  This change actually worked a lot better except for two things:
  1. You can search a treeview for a node via an attribute value but cannot search for a node via its UniqueID property.
  2. When you drag & drop a node its UniqueID value changes.

To resolve issue #1 I created this method:

    /// <summary>
    /// Every node has a Unique ID value.  There's no built-in method to locate a node in a treeview via its Unique ID.
    /// This method accomplishes that.
    /// </summary>
    /// <param name="treeView"></param>
    /// <returns></returns>
    public static RadTreeNode FindNodeByUniqueID(RadTreeView treeView, string uniqueID)
    {
      RadTreeNode foundNode = null;

      int nodeCount = treeView.GetAllNodes().Count;
      RadTreeNode[] allNodes = new RadTreeNode[nodeCount];
      treeView.GetAllNodes().CopyTo(allNodes, 0);

      foreach (RadTreeNode node in allNodes)
      {
        if (node.UniqueID == uniqueID)
        {
          foundNode = node;
          break;
        }
      }

      return foundNode;
    }


To resolve issue #2 I just stored the new [changed] UniqueID value into my PreviousID property.

Now I have a UI that works faster and there's actually a bit less code than before.  I'd say that's a Win-Win!!

Hopefully this will help someone else too,

Robert W.
http://MWTech.blogspot.com
0
Veronica
Telerik team
answered on 04 May 2010, 09:55 AM
Hello Robert,

Thanks you for sharing this.
We'll have it in mind for future similar questions.

Best wishes,
Veronica Milcheva
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.
Tags
TreeView
Asked by
Robert
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Robert
Top achievements
Rank 1
Share this question
or