The Load On Demand feature allows the developer to delay the population of RadTreeView
and save HTML output thus improving performance. RadTreeView supports three different
types of load on demand:
- Server-Side CallBack
- Server-Side
- Web Service
- Page Methods
To use a specific load on demand mode you need to set the ExpandMode
property of a RadTreeNode. When using Server-Side CallBack or Server-Side mode you need subscribe
to the NodeExpand event and create the tree nodes. Here is a sample
implementation:
C#:
protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e)
{
RadTreeNode onDemandNode = new RadTreeNode("Loaded on demand");
//Configure the node to populate on demand as well
onDemandNode.ExpandMode = TreeNodeExpandMode.ServerSideCallback;
//Add the node as a child of the currently expanded node
e.Node.Nodes.Add(onDemandNode);
}
VB.NET:
Protected Sub RadTreeView1_NodeExpand(sender As Object, e As RadTreeNodeEventArgs)
Dim onDemandNode As New RadTreeNode("Loaded on demand")
'Configure the node to populate on demand as well
onDemandNode.ExpandMode = TreeNodeExpandMode.ServerSideCallback
'Add the node as a child of the currently expanded node
e.Node.Nodes.Add(onDemandNode)
End Sub
For Web-Service load on demand you need to populate the WebServiceSettings
property of RadTreeView.
<telerik:RadTreeView ID="RadTreeView1" runat="server">
<WebServiceSettings Path="TreeViewWebService.asmx" Method="LoadNodes" />
</telerik:RadTreeView>
Then implement the method to return the nodes that are loaded on demand. Here is
a sample implementation:
C#
[ScriptService]
public class TreeViewWebService : WebService
{
[WebMethod]
public RadTreeNodeData[] LoadNodes(RadTreeNodeData node, object context)
{
List<RadTreeNodeData> result = new List<RadTreeNodeData>();
RadTreeNodeData node = new RadTreeNodeData();
node.Text = "Loaded on demand";
node.ExpandMode = TreeNodeExpandMode.WebService;
return result.ToArray();
}
}
VB.NET
<ScriptService> _
Public Class TreeViewWebService
Inherits WebService
<WebMethod> _
Public Function LoadNodes(node As RadTreeNodeData, context As Object) As RadTreeNodeData()
Dim result As New List(Of RadTreeNodeData)()
Dim node As New RadTreeNodeData()
node.Text = "Loaded on demand"
node.ExpandMode = TreeNodeExpandMode.WebService
Return result.ToArray()
End Function
End Class
Page Methods load on demand mode is very similar to Web Service. You need to set
the WebServiceSettings property and use set the ExpandMode property to WebService.
Make sure your page method is static and is marked with the WebService attribute.
<telerik:RadTreeView ID="RadTreeView1" runat="server">
<WebServiceSettings Path="Default.aspx" Method="LoadNodes" />
</telerik:RadTreeView>
C#
[WebMethod]
public static RadTreeNodeData[] LoadNodes(RadTreeNodeData node, object context)
{
List<RadTreeNodeData> result = new List<RadTreeNodeData>();
RadTreeNodeData node = new RadTreeNodeData();
node.Text = "Loaded on demand";
node.ExpandMode = TreeNodeExpandMode.WebService;
return result.ToArray();
}
VB.NET
<WebMethod> _
Public Shared Function LoadNodes(node As RadTreeNodeData, context As Object) As RadTreeNodeData()
Dim result As New List(Of RadTreeNodeData)()
Dim node As New RadTreeNodeData()
node.Text = "Loaded on demand"
node.ExpandMode = TreeNodeExpandMode.WebService
Return result.ToArray()
End Function