views:

202

answers:

3

I have a problem with expanding/collapsing a Treeview control in an Updatepanel which causes weird behavior and functions fine if placed outside the Updatepanel.

I have found that TreeViews is not supported in updatePanels so my question is:

  • What is a workaround to avoid a full postback whilst keeping expand/collapse functionality as well as TreeNode_clicks that updates another control?
  • Also why does it seem that some people use a TreeView inside an Updatepanel with success? Is this only an ASP2 prolbem?
A: 

TreeView in .Net 2.0 doesn't need to postback on expand/collapse.

Have you tried to put an UpdatePanel around the control you wish to update with a trigger

< asp:PostBackTrigger ControlID="treeView" />

GranadaFEUP
Yes did try but didn't work. The postbacks and updates seems to work fine. It is simply weird expand behavior when placing the treeview on an updatepanel which works fine without an update panel.
Pierre
A: 

It's the loading of the treeview javascript that fails under an updatepanel. I've tried putting some explanations and options below in bullet points.

  • The control will work in an updatepanel if it is visible straight away.
  • The control will not work in an updatepanel if it is made visible after a postback.
  • If you disable the client side javascript, the control will work in an updatepanel but will cause a postback every time a plus/minus is clicked.

Hope that helps

Matthew Steeples
The control is visible from the start. I don't really understand the "control will not work if made visible after a postback"? Its always visible. How do you disable client side javascript? Did you try this with ASP2 as I believe in ASP3 works fine- Thanks for your reply
Pierre
If the control is visible from the start then it should work. I think there's a property called "EnableClientScript" which, when set to false, will disable the javascript and make the control rely on postbacks.
Matthew Steeples
It worked! Doesn't make sense but thanks! Ideally I would like no postbacks on + or - clicked and only on selectedNodeChanged but this will do for now.
Pierre
A: 

As declared by Microsoft, treeview is not compatible with UpdatePanel. So you are having all the issues. I have managed the same to a quite acceptable level in one of my project. You can refer to the posts on the same as follows: http://www.geekays.net/post/Using-TreeView-inside-AJAX-UpdatePanel.aspx and http://www.geekays.net/post/TreeView-control-postbacks-on-check-and-uncheck-of-the-nodes-Checkbox.aspx

Let me know if it helps.

Kangkan
Thanks for the reply and info was useful but seems that if the treeview is visible and EnableClientScript is false then postbacks works fine on an updatepanel.
Pierre