views:

3759

answers:

4

how to?

I tried AutoPostback=false, but clicking on the node still posts the page back. Any ideas?

A: 

where on the control's declaration did you put the AutoPostback=false? Can you maybe edit to question to include your code so we can help you out?

FailBoy
I put it inside the TreeView declaration. Something like <TreeView runat="server" Autopostback="false" ...etc
gnomixa
+2  A: 

The default setting for EnableClientScript is true, so by default, expanding and collapsing of nodes should be happening client side. Note the remarks for that property though (Emphasis mine):

Use the EnableClientScript property to specify whether the TreeView control renders client-side script on compatible browsers to handle expanding and collapsing events. When this property is set to true, compatible browsers execute the code to expand and collapse nodes on the client. The tree node data must be known in advance for the client-side script to work. Using client script prevents a post back to the server each time a node is expanded or collapsed.

Things to check:

  1. You do have the node data avaiable to the tree view data source without a postback
  2. You haven't set EnableClientScript to false
  3. You're not using a control adaptor that's overriding this behaviour
  4. You aren't somehow confusing the server into thinking that you're a downlevel browser (that page is running on .NET 1.1 I think, so might be different to your server - it treats my version of IE with an overweight UserAgent string as "Downlevel" because the check cuts off after 128 characters, and fails)

If you can't have all the data available, then you should ensure that you are setting PopulateOnDemand, PopulateNodesFromClient and TreeNodePopulate correctly.


Response to comments

Yes, there's no reason why you can't do what you're attempting to do with a tree view control - indeed, it should do most of this for you - unless you aren't supplying the whole tree up front, in which case you'll need to supply the methods that will populate the nodes through PopulateNodesFromClient and TreeNodePopulate, assuming the browser is recognised correctly (those previous links have examples of both with and without postbacks).

The jQuery Tree View plugins will probably be more flexible (I've not used them so I wouldn't know - I have used the TreeView control we're discussing, but was getting the features "for free" because I only had a small tree, and was supplying all the data up front), but will require a bit more work to set up:

  1. You'll need to pull in the jQuery framework, if you're not already using it
  2. Write a web service that it can call to get the initial data along with subsequent nodes.
  3. Potentially worry about what happens to browsers with limited or no JavaScript support.

3 may or may not be the kicker for you - in everything we do, we try to use JavaScript to enhance functionality, not provide the functionality - as the jQuery library is all client side, if the browser doesn't support JavaScript, your jQuery TreeView control won't appear, and you'll possibly be losing a key navigational element, whereas a Server control like the ASP.NET TreeView control will notice that JavaScript isn't supported and resolve this for you by falling back to a server based (i.e. post-back) version of the control.

You should also remember that jQuery isn't a Microsoft thing (although they do now support it), and has been around for quite some time, and as a client side offering, it works independantly of the server technology - MS give us a number of "server" controls within the ASP.NET framework that we can use if we want to, and doing so can make our lives easier (usually in the short term anyway), but we don't have to - a prime example is the recently released ASP.NET MVC framework, which is a different way of building web applications on IIS using the .NET stack - but generally without the server controls.

Zhaph - Ben Duguid
Thanks! If I set these (PopulateOnDemand, PopulateNodesFromClient and TreeNodePopulate correctly.) properly, does this mean that my TreeView operates with the built in callback, w/o posting back the whole tree each time?
gnomixa
I'm slightly confused because even though MS claims that callback is built in in TreeView control, I still see JavaScript TreeView implementations such as JQuery TreeView etc. What's the difference in funcionality?
gnomixa
I need a tree that i will be able to seamlessly load (with callback) and w/o having the whole page reload, just the node selected, for ex. Looks like if I set these properties/functions properly I will be able to achieve this with asp.net TreeView. Do I have the right idea?
gnomixa
at the end, i went with jquery dynatree http://wwwendt.de/tech/dynatree/index.htmland it works beautifully with asp.net, no issued whatsoever. if anyone has any questions, i would be glad to answer.
gnomixa
A: 

The asp.net treeview does not support this functionality,

try obout treeview: http://www.obout.com/t2/index.aspx

It does load the nodes without reloading the whole tree.

mas_oz2k1
thanks. i went with the client side tree - dynatree. going client side in this case solved many issues - speed, the ease of use for example. http://wwwendt.de/tech/dynatree/index.html
gnomixa
A: 

A way forward.....

The automatic select action for each node is SelectExpand, the "Select" part of this enum is interpreted as "I've selected something and need to postback". To just "Expand" the node without causing a postback:

TreeView1.Nodes(0).SelectAction = TreeNodeSelectAction.Expand

Adam