Monday, July 7, 2008

Treeview runtime error on Panel - UpdatePanel - EnsurePanelFix

Today i came across a problem in a web part i was developing.

I had a treeview inside a panel which in turn was inside an Ajax UpdatePanel.

The normal panel had its visibility set to false by default. And in the web part, clicking a button sets the visibility of that panel to true. I used this method to toggle the visibility of the treeview and related controls that resided with it on the panel.

Upon implementing this along with the UpdateProgress control and the EnsurePanelFix method, i started getting runtime errors whenever i tried to expand any of the treeview's nodes (all are collapsed by default).

After spending a lot of time troubleshooting and looking for answers, i discovered that the EnsurePanelFix method was causing the problem. And just for clarity, i'm not using the code provided by microsoft but rather the following simplified version:
"_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;",

And so i have found that the ONLY workaround for this is to dynamically add and remove the nodes of the treeview instead of making it visible and invisible each time the toggle is performed.
Everything else can be left on a panel and that panel can be set to visible=true or false as much as you like without having it affect anything else.

Just make sure that you NEVER touch the .visibility property of the TreeView control.