Supressing Postbacks with ASP.Net 2.0 TreeView control

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 thoughts on “Supressing Postbacks with ASP.Net 2.0 TreeView control

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s