Click here to Skip to main content
Licence GPL3
First Posted 2 Oct 2007
Views 57,788
Downloads 550
Bookmarked 36 times

TreePane - A Control for the ASP.NET AJAX Toolkit

By | 2 Oct 2007 | Article
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:

<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:

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:

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)

About the Author

rodrigo diniz

Web Developer

Brazil Brazil

Member

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 .

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generaltreepane checknode Pinmembersalsigno8:53 10 Apr '09  
QuestionCan I expand TreePane nodes? PinmemberMember 208155323:20 17 Mar '08  
Hello,
First of all thanks for the great controls. For now I am using only TreePane. An have some questions.
I am new to all this Aspx.NET, Javascript. I try to integrate you controls to Sharepoint and got some problems:
 
1. I don't know how to expand tree nodes programically. Is there some sort of function or property which I mist?
 
2. In Sharepoint site I need to do some data filtration which depends on selected node. So I add some nodes in treepane, using Loader and function which I have taken from test site example, then I expand them, select one node (the node has got href, which has to open page, and by params, which I post to link, filter some sort data, the filter page is another story and it does not matter now) and it links me to another page, but the problem is that this link reloads whole page, so the treepane reloads again and after reload nodes are collapsed. But I don't want them to collapse, I understand that after reload all data is gone, and needes to fill up again, step by step.
So can you give me any hint on my problems ?
 
Sorry for my English.
 
Will be waiting for any answer.
 
Thank You again for great work.
Generalgreat article , thanks PinmemberEmad Omar15:50 29 Jan '08  
GeneralRe: great article , thanks Pinmemberrodrigo diniz23:36 29 Jan '08  
GeneralAdd parameters to the Request PinmemberSharif N17:20 11 Jan '08  
GeneralRe: Add parameters to the Request Pinmemberrodrigo diniz23:37 29 Jan '08  
QuestionJavascript error Pinmemberantivoland7:57 22 Nov '07  
AnswerRe: Javascript error Pinmemberrodrigo diniz22:48 22 Nov '07  
QuestionChanging the Tree Images Pinmembertundefama3:48 5 Nov '07  
AnswerRe: Changing the Tree Images Pinmemberrodrigo diniz3:56 5 Nov '07  
GeneralRe: Changing the Tree Images Pinmembertundefama5:05 5 Nov '07  
GeneralRe: Changing the Tree Images Pinmemberrodrigo diniz5:10 5 Nov '07  
GeneralRe: Changing the Tree Images Pinmembertundefama5:35 5 Nov '07  
GeneralRe: Changing the Tree Images Pinmemberrodrigo diniz5:41 5 Nov '07  
QuestionRe: Changing the Tree Images [modified] Pinmembertundefama5:02 6 Nov '07  
GeneralTreeNode Selection after postback PinmemberMoshe Fishman22:25 28 Oct '07  
GeneralRe: TreeNode Selection after postback Pinmemberrodrigo diniz23:54 28 Oct '07  
GeneralRe: TreeNode Selection after postback PinmemberMoshe Fishman21:03 29 Oct '07  
GeneralUsing Client API PinmemberMoshe Fishman21:20 21 Oct '07  
GeneralRe: Using Client API Pinmemberrodrigo diniz0:10 22 Oct '07  
GeneralRe: Using Client API PinmemberMoshe Fishman0:25 22 Oct '07  
GeneralRe: Using Client API Pinmemberrodrigo diniz0:32 22 Oct '07  
GeneralRe: Using Client API PinmemberMoshe Fishman0:42 22 Oct '07  
GeneralRe: Using Client API [modified] Pinmemberrodrigo diniz0:55 22 Oct '07  
GeneralRe: Using Client API [modified] PinmemberMoshe Fishman3:08 22 Oct '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 2 Oct 2007
Article Copyright 2007 by rodrigo diniz
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid