The beta 2 release of the CSS Friendly ASP.NET 2.0 Control Adapter kit supports more sophisticated features for the TreeView than previous releases. There are, however, a few limitations:
SelectedNodeChanged
If you wish to handle the TreeView's SelectedNodeChanged event, you must add a new attribute called OnAdaptedSelectedNodeChanged to your <asp:TreeView> tag. Set OnAdaptedSelectedNodeChanged equal to the name of a PUBLIC (!!!) function of your page that acts as the event delegate. Typically, you will end up with like this:
<script runat="server">
public void OnClick(Object sender, EventArgs e)
{
// do something with foobar.SelectedNode
}
</script>
<asp:TreeView ID="foobar" runat="server" OnSelectedNodeChanged="OnClick" OnAdaptedSelectedNodeChanged="OnClick" />
TreeNodeCheckChanged
The TreeNodeCheckChanged event is handled by the adapter in a fashion that parallels the SelectedNodeChanged event. In other words, when using the TreeView adapter, you should add OnAdaptedTreeNodeCheckChanged as a TreeView tag attribute and it should be set to the name of a PUBLIC function in the page that handles the event.
<script runat="server">
public void OnCheckChanged(Object sender, TreeNodeEventArgs e)
{
// do something with e.Node
}
</script>
<asp:TreeView ID="foobar" runat="server" OnTreeNodeCheckChanged="OnCheckChanged" OnAdaptedTreeNodeCheckChanged="OnCheckChanged" ShowCheckBoxes="Leaf">
To reiterate, to handle the TreeView's SelectedNodeChanged or TreeNodeCheckChanged events you must use a new attribute called OnAdapted[eventname]. And that attribute must be set to the name of a public (not protected) function that belongs to the page owns the TreeView.
Interestingly, the adapted Treeview handles the TreeNodePopulate event normally so you do not need to add any special attribute like OnAdaptedTreeNodePopulate to handle it. You can use the typical OnTreeNodePopulate attribute or set the delegate programmatically. Further, the delegate function need not belong to the page and can be protected, if you like.
Russ Helfand
Groovybits.com