Supressing Postbacks with ASP.Net 2.0 TreeView control

July 4, 2007

I’m working on a project at the moment that requires a navigation menu built with ASP.Net 2.0. The requirements dictate that the navigation elements should be configured in an XML file. This sounded perfect for the ASP.Net siteMap provider so I set about implementing a SiteMapDataSource and binding a TreeView control to it.

This worked fine however each top level menu item had to be collapsable with a ’scrolling’ animation and this was implemented using jquery. The only thing was, I didn’t want a postback to occur when the user clicked on each menu item which is the default action with the TreeView control.

In ASP.Net 1.1 you could set AutoPostBack property of the TreeView control to false and this would supress postbacks for every node. This property is missing in ASP.Net 2.0 so I set about finding a solution to the problem. Unfortunately there wasn’t much on the web about how to solve this particular problem but I did end up finding a solution that worked a treat.

For every node in the TreeView who you don’t want to cause a postback you should set it’s NavigateUrl property to javascript:void(0);

Now when a user clicks on the node a postback will not occur which is exactly what I needed.

3 Responses to “Supressing Postbacks with ASP.Net 2.0 TreeView control”

  1. Sergio Says:

    hi
    I’ve found this, take a look

    http://adoguy.com/viewrant.aspx?id=2042

    bye

  2. andreir Says:

    @Sergio : So practically the only difference is that the “ADO Guy” sets the Target to “_self” ?

  3. saleem Says:

    I found an article about using ajax on treeview in asp.net 1.1 at http://www.cool-tips.net/tree1.aspx. That’s working fine in Internet Explorer. But the problem is, that It is not working in FireFox. Plz help me in finding the solution.

    Thank You.

Leave a Reply