Failing AJAX Update? Check the Viewstate
I went around and around for several days on the case of the disappearing treeview. My client is using the excellent ComponentArt TreeView control wrapped inside an ASP.NET AJAX UpdatePanel with a Timer control to update the treeview contents every minute.
The treeview worked perfectly on a full page load but disappeared when the timer caused a partial page update. The scene was further complicated because there's a splitter pane or two involved.
I enlisted my friends at ComponentArt (I wrote their early documentation) and worked with Developer Support manager Stephen Hatcher* on and off for two weeks. We tried various scenarios and builds to fix or reproduce the problem.
It turns out that the issue had nothing to do with the control. Somewhere up the line, perhaps in the Web hoster's machine.config, the ViewState had been switched off. When the timer triggered a postback, the controls lost their "memory".
My "eureka" moment came when I analyzed the ViewState contents with Fritz Onion's ViewStateDecoder 2. The weird thing is that even when ASP.NET ViewState is off, there's still evidence of a viewstate in the page such as:
id="__VIEWSTATE" value="/wEPDwULLTE4OTU2NjkzNjBkZNwIdjnYZTJa5tc5V8uEAO47U+LR" /
The fix was to insert the following in the web.config:
<pages enableSessionState="true" enableViewState="true"
enableViewStateMac="true"
validateRequest="true">
</pages>
The preceding will either throw "It is an error to use a section registered as allowDefinition='MachineOnly' beyond machine.config" or (perhaps) enable the ViewState. Fortunately, it did the latter. Problem fixed.
Oddly enough, the client contacted me here in Victoria because of a comment on my Web site that I enjoy ASP.NET troubleshooting... It pays to advertise, I guess.
Thanks again to ComponentArt for lots of free support time on this, even though the missing ViewState actually had nothing to do with their product.
*Although his name is Stephen, he's more than likely to have someone else's name on his shirt. He buys brand new (but inexpensive) clothes from a uniform supply company. If the shirt with the name "Jake" sewn on the chest didn't fit Jake, the rejected item might show up on Stephen next week!