Click here to Skip to main content
13,589,969 members
Click here to Skip to main content
Add your own
alternative version


188 bookmarked
Posted 2 Mar 2003

TreeWeb - custom ASP.NET control

, 2 Mar 2003
Rate this:
Please Sign up or sign in to vote.
A tree control that can be used in every website based on ASP.NET.
<!-- Article image -->

Sample Image - TreeWeb.gif

<!-- Add the rest of your HTML here -->


There are not so many to say about this article. It simply offers an implementation for an ASP.NET custom tree control.

Almost three years ago I was trying to implement a tree control in raw asp ( At that time I realized how many things are missing the web developers that decided to implement their applications using Microsoft Technologies comparing with their colleagues that are using Java Technologies.

No longer after that I heard for the first time about the new technology (.NET) that Microsoft wants to have. From then I was trying in my free available time (which is not so much) to read about .NET and to keep track with the news about it. When I gathered enough information about .NET and the support it offers (not only) for the web applications developers on Microsoft platforms, I understood that finally they could compete with the Java web applications developers. With ASP.NET Microsoft jumped "tree big steps" ahead in supporting the web applications on Windows platforms.

UML Diagram

The diagram describes the basic architecture of the control. 

UML Diagram


TreeWeb class.


ElementsGets the elements collection of the tree.
CollapsedElementImageGets or sets the URL to the image that is showen for a collapsed element.
ExpandedElementImageGets or sets the URL to the image that is showen for an expanded element.
CheckBoxesGets or sets whether check boxes are displayed next to the tree elements in the treeweb control.
TargetGets or sets the default target for all tree elements action.
ImageListGets the collection of images urls for the TreeWeb control.
DefaultElementCssClassGets or sets the default CssClass for the tree elements.
DefaultElementCssClassOverGets or sets the default CssClass for the tree elements when OnMouseOver client event occure. [Not Implemented]

#ctorTreeWeb constructor
RaisePostBackEvent(IPostBackEventHandler.RaisePostBackEvent) Raise control specific events on post back.
LoadXMLLoads the tree structure from a XML file. [Not Implemented]
SaveXMLSaves the structure of the tree in a XML structure. [Not Implemented]
RenderRender the TreeWeb control.
SaveViewState(IStateManager.SaveViewState) Saves the changes of TreeWeb's view state to an Object.
LoadViewState(IStateManager.LoadViewState) Loads the TreeWeb's previously saved view state.
TrackViewState(IStateManager.TrackViewState) Instructs the TreeWeb to track changes to its view state.

ExpandOccurs when an tree element is expanded.
CollapseOccurs when an tree element is collapsed.


TreeElement class.


IDGets the ID of the TreeElement.
TextGets or sets the text to be displayed for the TreeElement.
ElementsGets the ElementsCollection for the TreeElement.
ParentGets the TreeElement parent object for the current element.
TreeWebGets the TreeWeb object.
IsExpandedGets whether the element is expanded or not.
HasElementsGets whether the element has or not children elements.
LevelGets the level where the element is in the tree.
IsCheckedGets whether the element is checked or not. [Not Implemented]
KeyGets or sets specific data for the tree element.
NavigateUrlGets or sets the action for the tree element.
TargetGets or sets the target of the tree element action.
CheckBoxGets or sets whether a check box is displayed next to the current element.
ToolTipGets or sets the ToolTip display text for the current element.
EnabledGets or sets whether the current element is enabled or not.
CssClassGets or sets the default CssClass for an element.
CssClassOverGets or sets the default CssClass for the element when OnMouseOver client event occure. [Not Implemented]
ImageIndexGets or sets the image index to be showen before the element in the tree.

#ctorTreeElement constructor.
#ctorTreeElement constructor.
#ctorTreeElement constructor.
ExpandExpand current element, it has effect only if it has elements.
CollapseCollapse current element, it has effect only if it has elements.
FindElementFinds a specified child element of current tree element.
SaveViewState(IStateManager.SaveViewState) Saves the changes of TreeElement's view state to an Object.
LoadViewState(IStateManager.LoadViewState) Loads the TreeElement's previously saved view state.
TrackViewState(IStateManager.TrackViewState) Instructs the TreeElement to track changes to its view state.

Using the code

... as any other web server control.

// build the tree structure inside the web form

<%@ Register TagPrefix="iiuga" Namespace="iiuga.Web.UI" 

             Assembly="TreeWebControl" %>

<iiuga:treeweb id="_treeWeb" runat="server" CollapsedElementImage="plus.jpg" 

    <iiuga:ElementImage ImageUrl="icon1.gif"></iiuga:ElementImage>
    <iiuga:treeelement text="Your Online Radio Stations" 

    <iiuga:treeelement text="Classic Rock & Oldie" 

           ToolTip="Classic Rock & Oldie">
        <iiuga:treeelement text="All Rock" ImageIndex="0" ToolTip="AllRock">
        <iiuga:treeelement text="Classic Rock" ImageIndex="0" 

        <iiuga:treeelement text="Elvis Rocks!" ImageIndex="0" 

        <iiuga:treeelement text="Oldies" 

    <iiuga:treeelement text="Classical" ToolTip="Classical" 

        <iiuga:treeelement text="20th Century" 

        <iiuga:treeelement text="Opera" ImageIndex="0" 

        <iiuga:treeelement text="Top Classical" 



// dynamically add elements inside the tree


protected iiuga.Web.UI.TreeWeb _treeWeb;

int _elementIndex = _treeWeb.Elements.Add( "New TreeElement" );
_treeWeb.Elements[_elementIndex].CssClass = "CssClass";
_treeWeb.Elements[_elementIndex].Key = "Key";
_treeWeb.Elements[_elementIndex].ToolTip = "New TreeElement ToolTip";

... at the end

The control is far from being complete, some of its methods are not yet implemented and are nice features that can be included. But how it is now covers the normal needs of any website developer, it is a base for somebody who wants to extends its functionality and is an example for everyone who starts to develop custom server controls. For getting new versions of the TreeWeb control, for reporting bugs or for asking me any questions please feel free to go to my webpage and do it. Thanks.


The article, as well as any accompanying source code and compiled binaries, are subject to local and international copyright laws and all rights are reserved by Iulian Iuga.

The code described in the article is available in the public domain and can be incorporated, either in its entirely or modified, into client applications. Permission is never granted for including, delivering or selling it as part of any collection of software tools.

When using or providing any of the accompanying code, please provide acknowledgment of the author. All final products must include the phrase "Portions copyright ) 2003 by Iulian Iuga" in the about screen, or where appropriate.

The source code and compiled binaries were never used in production environment and was never intended too, the author is not responsible for any damages produced by using it in that manner.


3 March 2003 - Submitted.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Iulian Iuga
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

Questionhow to check with this tree control Pin
khawar abbas zaidi7-Feb-06 2:38
memberkhawar abbas zaidi7-Feb-06 2: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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.180618.1 | Last Updated 3 Mar 2003
Article Copyright 2003 by Iulian Iuga
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid