RadTreeView for ASP.NET

Load On Demand Client-Side Send comments on this topic.
See Also
Load On Demand Support > Load On Demand Client-Side > Load On Demand Client-Side

Glossary Item Box

 

Nodes loaded on the client on demand (node.ExpandMode = ExpandMode.ServerSideCallBack) cannot take part in any postback events (NodeClick included) because the server is not aware of these nodes. (They have been added on the client). 


Telerik RadTreeView supports client-side load on demand. You can populate child nodes on demand without postback to the server. The mechanism is quite straight forward. Similar to the LoadOnDemand server-side, load the root nodes in the initial page request. For LoadOnDemand client side, make sure to set the ExpandMode property to ExpandMode.ServerSideCallBack, e.g.

  Copy Code
...
RadTreeNode rootNode = new RadTreeNode();
rootNode.Text =
"Root Node 1";
rootNode.ExpandMode = ExpandMode.ServerSideCallBack;
...


ServerSideCallBack makes sure that the appropriate NodeExpand event handler is fired server-side without postback (using async remote callbacks). In the NodeExpand event handler, you can check the EventArguments and get the node clicked, e.g.


  Copy Code
...
private void RadTree1_NodeExpand(object o, Telerik.WebControls.RadTreeNodeEventArgs e)
{
 
string nodeText = e.NodeClicked.Text;
 
string nodeValue= e.NodeClicked.Value
 ...
}
...


Please make sure you access only the ID, Text and Value properties of the node. Since the event is client-side async call, all other properties of the node, including ParentNode and Treeview are not set (and you can not use FullPath, Next, Prev or other RadTreeNode methods).

After you get the ID of the node clicked, you can perform the respective action - query database for the child nodes of the node with the respective ID, check sub-folders, etc (per your requirement), you can set all node properties as you wish, and add them to the Nodes collection of the clicked node, making sure you set the ExpandMode to ServerSideCallBack, e.g.


  Copy Code
...
foreach (RadTreeNode node in GetChildNodes(e.NodeClicked))
{
 node.ExpandMode = ExpandMode.ServerSideCallBack;
 e.NodeClicked.Nodes.Add(node);
}
...


Leave Telerik RadTreeView to take care of the rest automatically.

Generally, nodes loaded via callback (ServerSideCallBack) cannot take part in server events since the server is not aware of their existence (see note below). Nonetheless, you can still use NavigateUrl navigation, Targets, client-side Drag & Drop and all client-side events without any problems. Also, you can persist the expanded state of the TreeNodes after a postback. The workaround is a bit tricky and you should closely review the following example.

Storing the expanded state of TreeNodes added via callback


To store the nodes on the client-side and keep the client-side experience, you can use Telerik RadCallback along with Telerik RadTreeView.
For more details, please refer to:

A detailed example of using client-side load on demand can be seen here.

Whether you opt for using the inbuilt callback functionality of Telerik RadTreeView or for integrating Telerik RadTreeView with Telerik RadAjax, please note that you cannot combine the two approaches.

See Also