Click here to Skip to main content
Click here to Skip to main content

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.
Prize winner in Competition "ASP.NET Feb 2003"
<!-- Article image -->

Sample Image - TreeWeb.gif

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

Introduction

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 (http://www.codeproject.com/asp/treecontrol.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

iiuga.Web.UI.TreeWeb

TreeWeb class.

Properties

Elements Gets the elements collection of the tree.
CollapsedElementImage Gets or sets the URL to the image that is showen for a collapsed element.
ExpandedElementImage Gets or sets the URL to the image that is showen for an expanded element.
CheckBoxes Gets or sets whether check boxes are displayed next to the tree elements in the treeweb control.
Target Gets or sets the default target for all tree elements action.
ImageList Gets the collection of images urls for the TreeWeb control.
DefaultElementCssClass Gets or sets the default CssClass for the tree elements.
DefaultElementCssClassOver Gets or sets the default CssClass for the tree elements when OnMouseOver client event occure. [Not Implemented]

Methods
#ctor TreeWeb constructor
RaisePostBackEvent (IPostBackEventHandler.RaisePostBackEvent) Raise control specific events on post back.
LoadXML Loads the tree structure from a XML file. [Not Implemented]
SaveXML Saves the structure of the tree in a XML structure. [Not Implemented]
Render Render 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.

Events
Expand Occurs when an tree element is expanded.
Collapse Occurs when an tree element is collapsed.

iiuga.Web.UI.TreeElement

TreeElement class.

Properties

ID Gets the ID of the TreeElement.
Text Gets or sets the text to be displayed for the TreeElement.
Elements Gets the ElementsCollection for the TreeElement.
Parent Gets the TreeElement parent object for the current element.
TreeWeb Gets the TreeWeb object.
IsExpanded Gets whether the element is expanded or not.
HasElements Gets whether the element has or not children elements.
Level Gets the level where the element is in the tree.
IsChecked Gets whether the element is checked or not. [Not Implemented]
Key Gets or sets specific data for the tree element.
NavigateUrl Gets or sets the action for the tree element.
Target Gets or sets the target of the tree element action.
CheckBox Gets or sets whether a check box is displayed next to the current element.
ToolTip Gets or sets the ToolTip display text for the current element.
Enabled Gets or sets whether the current element is enabled or not.
CssClass Gets or sets the default CssClass for an element.
CssClassOver Gets or sets the default CssClass for the element when OnMouseOver client event occure. [Not Implemented]
ImageIndex Gets or sets the image index to be showen before the element in the tree.
IsTrackingViewState

Methods
#ctor TreeElement constructor.
#ctor TreeElement constructor.
#ctor TreeElement constructor.
Expand Expand current element, it has effect only if it has elements.
Collapse Collapse current element, it has effect only if it has elements.
FindElement Finds 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" 
        ExpandedElementImage="minus.jpg">
<ImageList> 
    <iiuga:ElementImage ImageUrl="icon1.gif"></iiuga:ElementImage>
</ImageList>
<Elements>
    <iiuga:treeelement text="Your Online Radio Stations" 
           CssClass="Sample3_Header">
</iiuga:treeelement>
    <iiuga:treeelement text="Classic Rock & Oldie" 
           ToolTip="Classic Rock & Oldie">
    <Elements>
        <iiuga:treeelement text="All Rock" ImageIndex="0" ToolTip="AllRock">
</iiuga:treeelement>
        <iiuga:treeelement text="Classic Rock" ImageIndex="0" 
               ToolTip="ClassicRock"></iiuga:treeelement>
        <iiuga:treeelement text="Elvis Rocks!" ImageIndex="0" 
               ToolTip="ElvisRocks!"></iiuga:treeelement>
        <iiuga:treeelement text="Oldies" 
              NavigateURL="javascript:alert('Oldies');"></iiuga:treeelement>
    </Elements>
    </iiuga:treeelement>
    <iiuga:treeelement text="Classical" ToolTip="Classical" 
           CssClass="Sample3_ElementNode">
    <Elements>
        <iiuga:treeelement text="20th Century" 
                ToolTip="20thCentury"></iiuga:treeelement>
        <iiuga:treeelement text="Opera" ImageIndex="0" 
                ToolTip="Opera"></iiuga:treeelement>
        <iiuga:treeelement text="Top Classical" 
                ToolTip="TopClassical"></iiuga:treeelement>
    </Elements>
    </iiuga:treeelement>
</Elements>
</iiuga:treeweb>

 OR

//
// 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.

Copyright

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.

History

3 March 2003 - Submitted.

License

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

Comments and Discussions

 
Questionhow to check with this tree control Pinmemberkhawar abbas zaidi7-Feb-06 2:38 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 3 Mar 2003
Article Copyright 2003 by Iulian Iuga
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid