Click here to Skip to main content
12,506,584 members (52,215 online)
Click here to Skip to main content
Add your own
alternative version

Stats

319.3K views
9.2K downloads
186 bookmarked
Posted

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

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

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]

Methods
#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.

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

iiuga.Web.UI.TreeElement

TreeElement class.

Properties

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

Methods
#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" 
        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

Share

About the Author

Iulian Iuga
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionJava Script for ExpandAll / Contract All Pin
LustForDotnet16-Jan-07 18:58
memberLustForDotnet16-Jan-07 18:58 
AnswerRe: Java Script for ExpandAll / Contract All Pin
prasanthikushal16-Jan-07 22:02
memberprasanthikushal16-Jan-07 22:02 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 3 Mar 2003
Article Copyright 2003 by Iulian Iuga
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid