ASP.NET TreeView - How to improve performance?

Introduction

This tutorial will instruct how to improve performance for loading a heavy tree with hundreds or even thousands of nodes. Basically, the idea is to reduce the HTML markup loaded from the server as much as possible. Following issues should be considered:

# 1
Shorten the path of loading styles, images for tree.
Instead of using default paths such as tree2/style or tree2/icons, create directories call t_s and t_i then move all css files to t_s, image files to t_i.
This way, "tree2/icons" will be replaced with "t_i" in the HTML markup of each node.

# 2
If links are used for each node and you want to apply special style for those links. Instead of using inline css style such as class="className", we could attach the style like this:
.ob_t2 a{ 
    // custom style
}
This way, we will shorten the properties of <a> tag.

# 3
If there is a case of using link inside the node as follow:
href="javascript:void(OpenThirdParty(150,6))"
Performance could be improved by shortenning the href property:
href="javascript:o3p(150,6)"
The "o3p" function can call the old "OpenThirdParty" function for proper implementation

# 4
In case that dynamic loading is applied, performance could be improved by shortenning file name which is used for dynamic load. File like SearchResultTreeview_OtherLevels.aspx could be renamed as srt_ol.aspx for example. Further more, query string could be shortened also.

For example:
SearchResultTreeview_OtherLevels.aspx?idclus=1&selid=460&RCT=7&NLV=AD&CompId=93
could be renamed as:
srt_ol.aspx?var=1_460_7_AD_93
On the server-side, the query string can be splitted and recreated for all the needed variables.

# 5
If easy menu is integrated with treeview, there is a better method for attaching easy menu to the nodes here.

Tip
  • Each child should have parent
  • ach top level node should have parent "root" (low case)
  • if you use property .ShowLost = true, it will slow down the tree, because for each node lost without parent, parent will be searched through all the tree. It will definitely slow down the treeview. Properties .ShowLost and .ShowLostRed are for debugging purpose only. See how to populate from database here

obout.com
obout.com Home
News
TreeView Home
TreeView Home
Download
Site Map
Examples 
Styles
Classic
Classic
Dynamic Loading
No Icons
Black
Black No Icons
Background image
Premiere New
black
blue
green
red
violet
yellow
Explorer
Gray
Help
HelpPlus
MSDN
TMenu
TMenu (small icons)
Vista New
Web
White
XPBlue
Win2003
Right To Left
Features
Drag and drop - 18
Drag-n-Drop
Custom
Multi-node
Dragging with children
Drop in textboxes
External D'n'D
Move nodes 1
Renumber nodes
Auto Scrolling
Copy / Move nodes
D'n'd and Dynamic Loading
Drop in listboxes
Drop in listboxes 2
Restrict Levels
D'n'D with various options
Disable dropping in two trees
Not-allowed Icon New
Sort after D'n'D New
Dynamic loading - 6
Web style
MSDN style
Deep tree
Reload subtrees
Loading trees partially
Virtual Scrolling New
Add/remove nodes - 4
Add/remove on client-side
Alphabetical order
Add to dynamic subtrees
Remove all children
Edit nodes - 4
Edit nodes
Nodes with Checkboxes
Sort after Edit New
Select nodes - 3
Find selected node
Select multiple nodes
Highlight parent
Layout - 2
Width, height and scrollbars
Root node
TreeView state - 3
Dynamic
Keep expanded
Keep collapsed
File system - 3
Show file system
File system loading
File system manager
Additional data for each node - 3
Details
On client side
Image viewer
Expand/collapse nodes - 2
By level
Single folder
Multiple trees - 4
Two Trees
Two Trees custom
Two Trees enhancement
Move Nodes BTWN Trees New
Different Styles New
Validation - 2
D-n-d on server
Edit on server
Integration - 14
With a context menu
Attach Easy Menu
Attach menu on-demand
Attach to dynamic nodes
Attach menu to icons
Change icons
With Flyout
With Splitter
MS AJAX
With checkboxes
Dynamic checkboxes
With a Combobox
With modal dialog
Outlook Slide Menu
With Tab Strip
Build from SiteMap
Customization - 7
Icons for treeview
Aligned columns
CSS Tutorial
Hover node effect
Multi-Level Slide Menu
Select on Collapse
From Dennis
From/To XML file
Keyboard navigation
Search nodes
Client-side events
Knowledge Base - 1
Knowledge Base
Documentation
Method Add
Server-Side
Client-Side
Client-Side Events
XML
Methods
XML Tutorial
Client-Side Tutorial
Tutorial 1
Tutorial 2
Tutorial 3
Tutorial 4
Events
Tutorial
Event handlers
Tutorials
Using the correct path
Improving performance
In a user control
AutoPostBack with various options
Open in Search pane
Move nodes by clicking a button
Postback on node select
Switch icons