TreeView and Web Services

Posted Wed Apr 23, 2008 @ 10:49 AM


In my previous post, I talked about the web service functionality that's common to all ComponentArt navigation controls. I focused on common features that are present in many different controls, especially in this case, but this approach was unfair to one control. With its ability to load chunks of data on demand, TreeView is the odd man out, supporting everything that other navigation controls do, but adding its own unique twist.

Like the other navigation controls, TreeView has control-level WebService and WebServiceMethod properties. These determine which ASP.NET AJAX registered web service will be called, and which method of that service, when nodes are retrieved. For the initial data load, the behaviour is identical to Menu, TabStrip or NavBar. What TreeView can do that others can not is to only load some nodes initially, letting user actions determine what else gets loaded and when. Essentially, TreeView is able to operate in load-on-demand mode with web services.

To return load-on-demand nodes (parent nodes with no child nodes pre-loaded), simply set their UseWebService property to true. This will notify TreeView to consider these nodes to be parent nodes, and to call the web service again when they are expanded, to load their child nodes. When that happens, the same WebServiceMethod will be called, but with a twist: the TreeViewWebServiceRequest object that is passed in will have its Node property set to the node that requires data. Based on the Text, Value or ID of this node, appropriate new nodes can be created and returned, as they would normally, from the web service method. Note that these child nodes can also have their UseWebService property set to true.

After a web service call completes, the client-side event also exposes the node for which the call was made, in addition to the customData property common to all navigation controls. Here's an overview of the client-side TreeViewNodeWebServiceCompleteEventArgs class:

function TreeView1_webServiceComplete(sender, eventArgs)
{
  var node = eventArgs.get_node();
  
  if(node)
  {
    alert('Completed web service call for node ' + node.get_text());
  }
  else
  {
    alert('Completed web service call for top level data.');
  }
  
  var customData = eventArgs.get_customData();
  
  if(customData)
  {
    alert('Web service call returned custom data: ' + customData);
  }
}

You can see an example of this functionality online with the TreeView Web Service Load-on-demand sample. Please note that this functionality is fully available only as of Web.UI 2008.1 SP1, released on April 23rd 2008.

Summary

To recap, since TreeView can load node-specific partial data through web services (unlike other navigation controls, which can only load all the items at once), its related API is a superset of, say, that of Menu. TreeViewWebServiceRequest includes the Node property (null for initial, top-level loading), TreeViewNode has the UseWebService boolean, and the client-side TreeViewWebServiceCompleteEventArgs class includes a node property. These extensions enable efficient load-on-demand functionality built entirely on ASP.NET AJAX web services.

Comments

BJ

Posted on Wed Apr 23, 2008 @ 10:49 AM

"... Web.UI 2008.1 SP1, released on April 23rd 2008". Can't seem to locate SP1

milos

Posted on Wed Apr 23, 2008 @ 10:49 AM

BJ, it's the current 2008.1 build (version 2008.1.1110) available for download. The download page doesn't specify that it's a service pack release and not the original 2008.1. Apologies for the confusion.

Posted on Wed Apr 23, 2008 @ 10:49 AM

This is definitely interesting techology and the strides you guys have made are most impressive. The big problem we've had with the treeview is getting persistance to work in a high-performance way out of the box. I'm hoping the recent versions have created a better way to deal with these problems. Here's the problem in a nutshell: Once the load-on-demand occurs, how does that data persist between postpacks? Well, the treeview builds an xml representation of its contents in a hidden field and sends that along with each postback/callback. Even for trees that only load-on-demand a few dozen items, this can become large. In our case we were dealing with dozens of nodes and it added 200k to the page - ouch. Here at Inntec, we tackled this problem in by re-writing the plumbing to store our persistance data in session state. This is more involved than it may sounds, involving code in three or four places plus some javascript and new hidden fields. This is painful and difficult to reproduce in an elegant way. Is there a better way with the recent improvements?

Michal Miszczyszyn

Posted on Wed Apr 23, 2008 @ 10:49 AM

Hello, But what if I want to populate whole tree from webservice call. I have a list of TreeViewNodes which is a result of some search operation, and now I want to populate TreeView with those nodes? TreeViewCollection, TreeViewWebServiceResponse are not getting serialized properly using JSON. Any ideas?

Posted on Wed Apr 23, 2008 @ 10:49 AM

Hi Milos,

          We are using CA treeview control to populate with various nodes, in which few of these nodes do contain few other sub-nodes. So, we are opting for treeviewnode "UseWebService" property by setting "WebService" and "WebServiceMethod" of treeview, to populate Nodes with sub nodes. So, here my question is, can we send any parameters to the "Completed" event from "WebMethod", so that I can control the flow of application at the client side. The reason is, in "WebMethod" we'll verify certain conditions, if those conditions are not met, then we'll redirect the client/user to another page.

Please let me know how can we accoplish this?

Kindly revert, If you need more explanation.

Thank you

Praneeth

Click here to log in or create an account.