Click here to Skip to main content
15,881,248 members
Articles / Web Development / HTML
Article

TreePane - A Control for the ASP.NET AJAX Toolkit

Rate me:
Please Sign up or sign in to vote.
4.45/5 (14 votes)
2 Oct 2007GPL31 min read 107.5K   1.2K   37   30
Development of an ASP.NET AJAX Control

Introduction

I wanted to develop a pack of controls wrapping the ExtJs JavaScript Framework. However, I never liked the way in which usual controls are developed, by mixing the JavaScript code with the C# code.

So I looked into the source of the ASP.NET AJAX control toolkit and I finally found what I wanted - a complete separation of JavaScript and .NET code.

The control has some features that the .NET Treeview does not have:

  1. Drag and drop nodes (just set enableDD to true)
  2. Editable nodes (just set the Editable property to true)
  3. Server-side events for node moved and node edited

See the tree live here and here.
To join the project, click here.
To see samples for all the controls in the DLL, click here.

Using the Code

Just add the DLL for the controls to your toolbox, drag and drop to your ASPX page and set some properties:

ASP.NET
<cc1:TreePane ID="TreePane" Editable="true" enableDD="true"
    Loader="TreeHandler.ashx" Width="400px" runat="server"
    OnNodeEdited="TreePane_NodeEdited" OnNodeMoved="TreePane_NodeMoved"
    OnContextMenuClicked="TreePane_ContextMenuClicked">
</cc1:TreePane>

You can add nodes to the tree in the designer or through code:

C#
GridControl.TreeNode root = new GridControl.TreeNode();
root.id = "0";
root.leaf = false;
root.text = "root";
TreePane.TreeNodes.Add(root);

To load nodes dynamically, you can use the Loader property of the control. The code for the loader page looks something like this:

C#
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
    TreeNode no = new TreeNode();
    no.draggable = true;
    no.id = ds.Tables[0].Rows[i]["id"].ToString();
    no.text = ds.Tables[0].Rows[i]["text"].ToString();
    //see if the node has children
    no.leaf = !HasChildren(ds.Tables[0].Rows[i]["id"].ToString());
    no.parentNodeId = context.Request["node"];
    nodes.Add(no);
}

JavaScriptSerializer ser = new JavaScriptSerializer();
context.Response.Write(ser.Serialize(nodes));

Points of Interest

The control was created with the events all fired through callback, then I was surprised while trying to integrate it with the Update Panel. The events where not being fired!

So after some researching and thinking, I implemented postback for the events and added a new property (AutoPostBack) to the control and voila! The events were working and the Update Panel was making them happen without a refresh.

History

This is a year old CodePlex project that has other cool controls.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Web Developer
Brazil Brazil
I am Web Developer since 1999 , and I am a
Microsoft Certified Professional since 2005.
I work with asp.net and c# since 2003.
Extender Samples .

Comments and Discussions

 
GeneralRe: Using Client API Pin
Moshe Fishman22-Oct-07 0:25
Moshe Fishman22-Oct-07 0:25 
GeneralRe: Using Client API Pin
rodrigo diniz22-Oct-07 0:32
rodrigo diniz22-Oct-07 0:32 
GeneralRe: Using Client API Pin
Moshe Fishman22-Oct-07 0:42
Moshe Fishman22-Oct-07 0:42 
GeneralRe: Using Client API [modified] Pin
rodrigo diniz22-Oct-07 0:55
rodrigo diniz22-Oct-07 0:55 
GeneralRe: Using Client API [modified] Pin
Moshe Fishman22-Oct-07 3:08
Moshe Fishman22-Oct-07 3:08 
GeneralCompile error Pin
ChuckH9-Oct-07 5:52
ChuckH9-Oct-07 5:52 
AnswerRe: Compile error Pin
rodrigo diniz9-Oct-07 9:51
rodrigo diniz9-Oct-07 9:51 
GeneralRe: Tree with Checkboxes sample Pin
grundt3-Oct-07 8:06
grundt3-Oct-07 8:06 
Do you have any plans to add a cascade feature to the tree with checkboxes (i.e. if you check/uncheck a parent node, it would propagate to all children, recursively )
GeneralRe: Tree with Checkboxes sample Pin
rodrigo diniz4-Oct-07 0:51
rodrigo diniz4-Oct-07 0:51 
GeneralRe: Sample: Tree with Checkboxes - compile error Pin
rodrigo diniz2-Oct-07 9:38
rodrigo diniz2-Oct-07 9:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.