OnClientNodePopulating
The OnClientNodePopulating client-side event occurs just before child nodes are loaded on-demand. The ExpandMode property of the parent node should be ServerSideCallback or WebService for this event to fire. The event can be canceled.
The event handler receives parameters:
-
The TreeView instance that fired the event.
-
Event arguments with functions:
-
get_node() retrieves a reference to the clicked on node.
-
get_context() retrieves an object that is automatically passed to a load-on-demand web service.
-
set_cancel() - call this function to specify whether the event should be canceled (true) or not (false).
-
get_domEvent() retrieves a DOM event object of the node population.
The example below shows how to prevent populating a "Network Locations" node. Note that the OnClientNodePopulated event does not fire when set_cancel() is called. See the Webservice Load-On-Demand topic for another example.
<telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server" OnClientNodePopulated="ClientNodePopulated"
OnClientNodePopulating="ClientNodePopulating" OnNodeExpand="RadTreeView1_NodeExpand">
<Nodes>
<telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="Search" ImageUrl="~/images/search.ico"
Expanded="True" Value="1">
<Nodes>
<telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack" Text="Recent Searches">
</telerik:RadTreeNode>
<telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack" Text="Network Locations">
</telerik:RadTreeNode>
</Nodes>
</telerik:RadTreeNode>
</Nodes>
</telerik:RadTreeView>
The server NodeExpand event handler for the RadTreeView defined above:
protected void RadTreeView1_NodeExpand(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
{
if (e.Node.Text == "Recent Searches")
{
for (int i = 1; i <= 10; i++)
{
e.Node.Nodes.Add(new Telerik.Web.UI.RadTreeNode("Search " + i.ToString()));
}
e.Node.ExpandMode = Telerik.Web.UI.TreeNodeExpandMode.ClientSide;
}
if (e.Node.Text == "Network Locations")
{
for (int i = 1; i <= 10; i++)
{
e.Node.Nodes.Add(new Telerik.Web.UI.RadTreeNode("Location " + i.ToString()));
}
e.Node.ExpandMode = Telerik.Web.UI.TreeNodeExpandMode.ClientSide;
}
}