Javascript – ASP.NET TreeView performance

asp.netjavascriptperformancepostbacktreeview

What would be the advisable thing to do to maximize the performance while using TreeView?

By maximize the performance, i mean minimize the number of trips between client to server, ie postbacks.

Would that mean then, that most of my Business logic will sit in the Javascript? What would be the compromise here?

I am talking about ASP.net TreeView server control

Best Answer

First, decide where you want to put your programming logic: for speed, it's better to use some other tree view control (that doesn't use table layout) and javascript framework to handle click events. I recommend using plain old ashx handler files for AJAX communication, they have less overhead than aspx and calling page methods. AJAX calls and results must contain only JSON or XML formatted data, not HTML.

On the oher side, RAD tool like VS and TreeView control offers quick production of web application, but of course with some penalties: you need to go back to server to handle every click/select event, which draws issues with whole page life cycle processing and huge amount of data transfer for ajax calls (ViewState along with HTML are transferred from server to client for every ajax event).

But if you want to stick with TreeView, i recommend:
- CSS Friendly Control Adapter: they greatly reduce size of generated html (in my case, from 100kb to 20kb of html) and replace table layout with ul/li elements
- Wrap TreeView inside ASP.NET AJAX UpdatePanel, but just treeview, and use conditional updates of panel. Don't be afraid to use several updatepanels
- keep ViewState minimal