ASP.NET TreeView - Using Server-Side Events

Step 1: Page set up

By default, TreeView needs two pages to be able to process events:

1. Default.aspx – This is where your tree is displayed. You can name this page any way you like.
2. TreeEvents.aspx – This page will process all your tree events.

Obout TreeView uses AJAX Page to notify the server of its actions. It does so by posting event details to TreeEvents.aspx page.

Suite download includes TreeEvents.aspx file that contains all event handlers for your convenience. There is also a fully functional example, called All Events, that this tutorial is based on.
Step 2: Add AJAX Page

Add AJAX Page control to Default.aspx and TreeEvents.aspx by inheriting the pages from AJAXPage

Directly on aspx page:
    <%@ Page Language="C#" Inherits="OboutInc.oboutAJAXPage" %>

In code behind:
C#
	public class PageName : OboutInc.oboutAJAXPage { ... }

VB.NET
	Public Class PageName Inherits OboutInc.oboutAJAXPage { ... }
Step 3: Listing events

You need to tell TreeView about all events that you will be handling. To do this you must list them in EventList property.

oTree.EventList = "OnNodeSelect,OnNodeDrop,OnAddNode";


The following events are available:
  1. OnNodeSelect
  2. OnNodeEdit
  3. OnNodeDrop
  4. OnAddNode
  5. OnRemoveNode
  6. OnNodeExpand
  7. OnNodeCollapse
  8. OnBeforeNodeEdit
  9. OnBeforeAddNode
  10. OnBeforeRemoveNode
  11. OnBeforeDrop
  12. OnMoveNodeUp
  13. OnMoveNodeDown
Step 4: Defining event handlers

For each event that you listed in step 3, you must define a public server side function in TreeEvents.aspx

For example, here is a function for OnNodeEdit in C#

public string OnNodeEdit(string id, string text, string prevText) {
	//update database
	
	return "Node successfully updated";
}

Each handler has different amount of arguments, depending on the event.

See list of handlers and their arguments.

That's it! Now on each tree event, a corresponding server side event handler will get executed in TreeEvents.aspx

We strongly recommend to check All Events example in the TreeView section of suite examples.
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