The ASP.NET 2.0 CSS Friendly Control Adapters 1.0 are fantastic tools. Really amazing; you simply drop in 30 pre-built files into your application and your TreeView, Menu, GridView and various login controls stop spitting out table-based layouts and start generating CSS-compliant code. Oh yeah, it's fantastic.
So here I am, happily pounding out CSS formatting, dropping my login controls building, and merrily moving along my way when I dropped in the TreeView control, went to view the new page and WHAMMY!
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Love affair over.
Far too many hours later I was able to determine that a very small piece of code on my master page was the root of the TreeView's problems. I had a footer that was simply writing some standard copy along the lines of, "this site ©2007 My Company" and was dynamically generating the 2007 with the following code:
<%= DateTime.Now.Year.ToString() %>
Removing that code resulted in a running page. Although removing this code and replacing it with a Label object would be a solution, I have a bad feeling this bug would come back to haunt me some time in the future.
Luckily, I found a solution buried in the forums at ASP.NET, specifically this one from Dmitry Karpenkov dated 4/4/2007. Add a private string, a method for it, and change the SaveAdapterViewState() method for the TreeView and you're back to work. I do need to really inspect the fix to find out if there are any negative results, but for now, I'm moving on.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.