I was just playing about with the treeview control adapter, having used the default template project provided from the site. I just stuck a treeview on the default.aspx page, which doesn't have a server form (which I realised was the problem), and then bound it to a sitemap. The control seemed to render, but I got javascript errors when I tried clicking on any of the buttons to expand and collapse the nodes. I couldn't figure out what I'd done wrong, but then I removed the mapping to the adapter in the browsers file and got the following error:
Control 'TreeView1' of type 'TreeView' must be placed inside a form tag with runat=server.
The problem was obvious from this message, but the adapted rendering had failed to throw this error. Fortunately I've got a copy of .NET Reflector, so I could see inside the RenderContents method of the System.Web.UI.WebControls.TreeView class, and I noticed the following call:
protected internal override void RenderContents(HtmlTextWriter writer)
{
base.RenderContents(writer);
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(this);
}
...
So I thought I'd try my luck at putting that code into the RenderContents method of the adapter, as follows:
protected override void RenderContents(HtmlTextWriter writer)
{
TreeView treeView = Control as TreeView;
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(treeView);
}
.....
And guess what, it works! I had a similar problem with another control, and I was scratching my head trying to figure out what was wrong, when I found that there are subtle differences like this which could cause a lot of development time to be lost. After all, the only difference between the tailor-made and adapted rendering should be the mark-up itself...
Could anybody have a look at putting this code into the next release?
cheers