ASP.Net 2.0’s TreeView Control

Posted on March 22nd, 2007 in Tech by Justin

Shoot the schitzo-fucker in the head.

Now, here’s a control that’s been pissing me off for a while now and it really hit the head today at work.

I’ve created a User Control in my current project that’s basically an encapsulation of nothing but an ASP.Net 2.0 TreeView control that operates as a simple selector for some hierarchical data. You select the item from the TreeView, it’s highlighted, and then the other side of the page reflects the properties of that particular item.

Today I set forth in modifying the control so that you could slap some checkboxes next to the items in question so you can assign those properties to another object. Seems simple enough, and the standard ASP.Net 2.0 control has a handy little property that lets you quickly flip it into said mode. Checkboxes show up handily right next to each item in the hierarchy.

I’m just not sure what the fuck the actually do!

Checking the checkbox yields no PostBack. That’s fine, I wouldn’t expect it to. However, there’s no option for making this happen. The one solution I found online for this was to render the control into an HTML writer and then do a search and replace on the checkboxes’ HTML to add an onClick event to call some custom JavaScript that would force another control to PostBack.

Workable, but I didn’t like the idea of doing a search/replace on HTML generated by a control. There had to be a better, more concrete, way of doing that.

Nope, it seems there isn’t.

Further, I found that with the checkboxes rendered I’d still get a PostBack if I clicked on a node’s text. That’s why I’m refering to the control as “schitzo” — it’s got two personalities. That doesn’t make any logical sense from a UI standpoint but was a bit giddy about this, because I presumed that I’d be able to select my checkboxes, then select a node, and achieve the desired functionality. That wouldn’t be a final solution, but it would have been somewhat promising.

That didn’t work either: My control wasn’t sending back the newly selected values.

I’m junking the whole thing. I’m going to instead try running with the TreeView control from the AJAX/Atlas project from Microsoft. I have no intention what-so-ever of actually using AJAX but the control comes bundled with the package and I figure it’ll at least be possible to get what I want done with that one.

Ugh. The life of a geek.