When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Wednesday, July 25, 2001

A Dynamic Tree Menu System
By Sam Reynoso


An Improved Version of the Dynamic Tree Menu System
Sam Reynoso has released an improved version of his Dynamic Tree Menu System. This improved version can be found at: Enhancing the Dynamic Tree Menu System. You are, however, strongly encouraged to read this first article in its entirety before attempting to "upgrade" to Sam's latest version.

- continued -

Introduction
Navigation systems are one of the most important aspects of any application. When properly developed, a navigation system enables users to quickly find the information they are searching for. One of the most effective of these has been the tree-based model seen in applications like Windows Explorer, the Microsoft Management Console, and the Registry Editor. The information is displayed in a hierarchical order with the broadest topic displayed at the top and related items stored underneath. Users like this type of navigation because the organized layout of the menu helps them reach their information with a minimum number of mouse clicks.

Web-based applications brought with them the same requirement for a user-friendly and intuitive way of navigating through an application. Early navigation systems were nothing more than a series of HTML hyperlinks connecting all the pages on a site. Even with the addition of nice graphics, some applications had more links than they could neatly present on the page. To solve this problem, developers began to mimic the tree navigation structures seen in traditional windows applications.

The easiest solution to code was a hard-coded HTML page that displayed the different states of the tree - open, closed, etc. However, this required repeated calls to the server to retrieve the appropriate HTML page. Furthermore, this solution became a maintenance nightmare as more nodes were added to the tree.

Java applets were also developed to address this issue. While they were easy to add to the page, and easy to maintain, they still had the extra overhead of having to be downloaded into the user's browser.

To get around the applet problem, some developers turned to pure javascript as their solution. Two of the more popular javascript tree menus are freely-available ( Joust by Ivan Peters and Tree Menu by Morton Wang).

While javascript provides a method of displaying a quick-loading dynamic navigation system, the code can be difficult to maintain and enhance. Debugging can be particularly difficult since the developer cannot view the source code generated by javascript.

An Alternative Solution
I was working on a web application that required that the user be able to easily navigate a site with potentially hundreds of links. The tree navigation system met this requirement perfectly. We needed a tree menu that would expand and collapse very fast without repeated trips to the server. The page also needed to download fast, so that excluded java applets. We finally settled on a 100% javascript solution and proceeded to integrate it into our application. The code we chose worked but it was extremely difficult to fix the subtle javascript bugs we found, and it was almost impossible to add new features. After reviewing the other popular javascript solutions available, I became convinced that an easy to maintain dynamic navigation menu system could be developed with only a handful of javascript and ASP functions.

The final solution was completed using the following technologies:

  • XML - stores data used to build the tree
  • ASP - dynamically generates HTML and javascript code
  • Javascript - controls the expanding/collapsing of menu items

Figure 1 below shows an example menu generated with this solution (you can also view a live demo):

An expanded tree menu.

XML for Data Storage
The Dynamic Tree Menu System I created builds a tree using data stored in a properly structured XML file. Using an XML file to store the content of the menu gives developers the ability to easily update the tree menu by modifying the XML text file.

The XML file is first loaded into an instance of the Microsoft XML Parser object (MSXML 3.0 SP1). The XML parser is available as a free download from Microsoft. If there are any errors in the XML file, the user is notified with a detail message. A simple menu could be displayed in XML like this:

<country type="root" value="United States of America"
            url="content.asp?page=usa">
   <states type="folder" value="States" url="content.asp?page=states">
      <state type="document" url="content.asp?page=ca"
                value="California"/>
   </states>
   <hist_fig type="document" value="Historical Figures"
                url="content.asp?page=histfig"/>
</country>

XML resembles HTML in its use of tags and attributes. However, XML does not limit the developer to a set of pre-defined tags and attributes. Instead the developer is free to define their own to serve their unique needs.

Unlike the HTML parsers in most browsers, XML parsers are very strict. For example, all tags must be terminated properly and attribute values must be enclosed in quotes. For tags like the <country> tag in the example above, you should make sure to close it with an ending </country> tag. Tags without content should be terminated with a /> as seen in the <hist_fig /> tag above.

In the XML file used by my Dynamic Tree Menu System, each XML tag contains the attributes type, value, and url. Developers can add more attributes as necessary, but the current example requires only these attributes. The Type attribute can contain one of these values: root, folder, or document. This attribute determines the type of icon used for the data element in the tree. The Value attribute contains the text that will be displayed for the data element. The URL attribute contains a link to follow when that data element is clicked.

Once the XML file is successfully loaded into the parser, ASP code can manipulate the XML DOM (Document Object Model) to generate the HTML needed to display the elements of the navigation tree. (For more information on XML, be sure to check out the XML Article Index.)

In Part 2 we'll continue our examination of this tree-based navigation system by looking at the needed ASP, HTML, and client-side JavaScript.

  • Read Part 2!


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES