Sunday, September 21, 2008

State of new nodes is lost when using ManualSmartCallbacks for WebTree

In NetAdvantage 2006 Volume 1, WebTree introduced two additional modes of performing load-on-demand operations: ManualSmartCallbacks and AutomaticSmartCallbacks. The purpose of these values is to provide similar functionality to their Manual and Automatic counterpart settings, but utilizing the out-of-band callback capabilities of SmartCallbacks (a.k.a. AJAX requests).

For the AutomaticSmartCallbacks setting, the functionality is quite similar to the Automatic setting where a datasource is utilized to rebind the tree on each callback to read in the appropriate nodes. The state of the tree is also maintained automatically by the tree, so that it knows which nodes have been expanded and which have not.

For ManualSmartCallbacks, however, the job of maintaining the state of the nodes falls to the application. The only value that is tracked by WebTree is the DataPath property of the node. This value is sent back to the server when a node is expanded on the client and is available on the e.Node.DataPath property within the DemandLoad event on the server. Thus, every node that is populated with the ShowExpand property set to true should also have the DataPath property set to a string that can be used to retrieve the children of the node when the user clicks to expand it. This is correct behavior.

When AutomaticSmartCallbacks are being used, WebTree sets the DataPath property to the XPath expression that corresponds to the node within the XmlDataSource.

In general, if data can be fetched from an XmlDataSource using CLR 2.0, then using AutomaticSmartCallbacks is easier and more functional than using ManualSmartCallbacks.

The limitations of ManualSmartCallbacks may render it unsuitable for use in situations where the full page must be posted back to the server and the full state of all expanded nodes needs to be recreated by the application. In such cases, the preexisting value of Manual should continue to be used. With LoadOnDemand.Manual set and ViewState enabled, the WebTree is able to reconstruct the node structure on a full postback of the page.

If you are using NetAdvantage for .NET 2006 Volume 3 or later, you can still achieve AJAX functionality without incurring the limitations of ManualSmartCallbacks. Place your WebTree inside a WebAsyncRefreshPanel (or "WARP"), and set the LoadOnDemand property to Manual instead. This gives the flexibility of Manual load-on-demand, including the persisting of the tree's node structure, while providing AJAX functionality via the WARP.

No comments: