Click here to Skip to main content
6,594,932 members and growing! (15,515 online)
Email Password   helpLost your password?
Web Development » Custom Controls » General     Intermediate

ASP.NET Dynamic XML Web Menu Control based on JavaScript

By Krishna_accent

ASP.NET dynamic XML web menu control based on JavaScript.
C#, Javascript.NET 1.0, Win2K, WinXP, Win2003, Vista, ASP.NET, Dev
Posted:8 May 2005
Updated:22 Sep 2005
Views:163,722
Bookmarked:74 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
26 votes for this article.
Popularity: 4.89 Rating: 3.46 out of 5
4 votes, 15.4%
1

2
5 votes, 19.2%
3
5 votes, 19.2%
4
12 votes, 46.2%
5

Introduction

This is a free web based menu (JavaScript enabled) control. There are not many web menu controls available that support dynamic menu creation and binding. This WebMenu control supports dynamic menu creation, XML menu binding and also DataSet binding. This control uses triga (free script) JavaScript menu internally. Any complex menu structure can be represented using a simple XML schema. Menu position and style can be easily applied and changed dynamically without affecting the web application.

Steps to setup WebMenu

  1. Create a new ASP.NET web project, right click on ToolBox; choose 'Add/Remove items' and add the SuperControls.WebMenu.dll reference (compile SuperControls.WebMenu.cproj to get the DLL).
  2. Copy the JS files menu_tpl.js and menu.js to the root directory of the site.
  3. Copy menu stylesheet menu.css file to the subdirectory css.
  4. Copy menudata.xml to the root directory.
  5. Create an ASPX file and drag and drop the WebMenu control to the WebForm and use one of the methods (given below) to bind the XML/dynamic data to the menu control.

ASPX Code

<cc1:WebMenu id="WebMenu1" MenuXMLPath="\\ServerName\rad\menudata.xml" 
                                        PadWidth="24" runat="server">
</cc1:WebMenu>
<!--
Other samples
//**********************************************************************
<cc1:WebMenu id="WebMenu2" MenuXMLPath="ServerName\rad\menudata.xml" 
                      ImageArrow="<img src=images\\arrow.gif border=0" 
                      PadWidth="22" runat="server">
</cc1:WebMenu>
<cc1:WebMenu id="WebMenu3" MenuXMLPath="\\ServerName\rad\menudata.xml" 
                           ImageArrow="" PadWidth="26" runat="server">
</cc1:WebMenu>
-->

Ways of binding menu items dynamically...

Method 1

Set MenuXMLPath property with the path of the XML menu file in the server.

Method 2

Create new DataSet with the XML file and bind to the web menu control.

For example:

       DataSet dsMenu = new DataSet();
       dsMenu.ReadXml(@"\\ServerName\rad\menudata.xml");
       WebMenu1.DataSource = dsMenu;

Method 3

Get the menu data from database and populate the DataSet with the following structure:

  • Column 1 : menuid (unique ID of menu item).
  • Column 2 : name (name of the menu item).
  • Column 3 : root (parent of the menu item. If it is the starting/root item then the root value will be "" else it will be the value of the parent menuid).
  • Column 4 : url (URL for the menu item).

For example:

 WebMenu1.DataSource = dsMenu;
 // (Sample DataSet is given below.)

XML menu file (sample)

<?xml version="1.0" encoding="utf-8" ?> 
<menu>
    'Level 0 nodes
    <menuitem root="" name="Search Sites" menuid="1" />
    <menuitem root="" name="Webmail Sites"  menuid="2" />
    <menuitem root="" name="DotNet Sites"  menuid="3" />
    
    'Level 1 Items
    <menuitem root="1" name="Google" url="http://www.google.com" 
                                                        menuid="11"/>
    <menuitem root="1" name="Altavista" url="http://www.Altavista.com" 
                                                        menuid="12"/>
    
    'Level 1 Items
    <menuitem root="2" name="Hot-mail" url=""  menuid="21"/>
        'Level 2 Items
        <menuitem root="21" name="Hotmail" url="http://www.hotmail.com" 
                                                          menuid="211"/>
        <menuitem root="21" name="MSN" url="http://www.MSN.com" 
                                                          menuid="212"/>
        
    <menuitem root="2" name="Yahoo" url="http://www.yahoo.com" 
                                                           menuid="22"/>
    <menuitem root="2" name="Rediff" url="http://www.rediff.com" 
                                                           menuid="23"/>
    
    'Level 1 Items
    <menuitem root="3" name="Microsoft" url="http://www.Microsoft.com" 
                                                           menuid="31"/>
    <menuitem root="3" name="GotDotNet" url="http://www.GotDotNet.com" 
                                                           menuid="32"/>
    <menuitem root="3" name="CodeProject" url="http://www.CodeProject.com" 
                                                           menuid="33"/>
    <menuitem root="3" name="ASpdotnet" url="http://www.ASpdotnet.com" 
                                                           menuid="34"/>
    
</menu>

In the above sample, the root attribute represents the parent of the menu item. The root attribute will be empty for parent/level zero menu items.

Sample dynamic menu DataSet (with one DataTable)

root name menuid url
Search Sites 1
Webmail Sites 2
DotNet Sites 3
1 Google 11 http://www.google.com
1 Altavista 12 http://www.Altavista.com
2 Hot-mail 21
21 Hotmail 211 http://www.hotmail.com
21 MSN 212 http://www.MSN.com
2 Yahoo 22 http://www.yahoo.com
2 Rediff 23 http://www.rediff.com
3 Microsoft 31 http://www.Microsoft.com
3 GotDotNet 32 http://www.GotDotNet.com
3 CodeProject 33 http://www.CodeProject.com
3 ASpdotnet 34 http://www.ASpdotnet.com

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

Krishna_accent


Member
Software Engineer from India,Working in .NET for 2 years.
Location: United Arab Emirates United Arab Emirates

Other popular Custom Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 96 (Total in Forum: 96) (Refresh)FirstPrevNext
GeneralI cant see the menu PinmemberKoval_Prad5:18 6 Oct '09  
Generalcant see anything Pinmembernandakumarse0:40 2 Jul '09  
Generalmenus position [modified] Pinmembersooberfellow22:15 30 Jun '09  
GeneralOracle connectivity Pinmemberkvalli23:32 15 Apr '09  
GeneralHow can i set the target frame.. Pinmemberryanjoseph15:53 8 Feb '09  
GeneralMicrosoft JScript runtime error: 'menu' is undefined PinmemberMember 161041521:14 23 Nov '08  
Generalunable to download the zipped file PinmemberMember 420613219:50 13 Aug '08  
Generalset menu as vertical and horiz Pinmemberramakrishna_yl22:25 18 Nov '07  
GeneralThank u a lot Pinmemberramakrishna_yl1:50 24 Oct '07  
GeneralSystem.StackOverflowException Pinmemberramakrishna_yl0:50 24 Oct '07  
GeneralCan not see anything Pinmemberalexaz110:28 12 Oct '07  
Generalkewl Pinmemberchullan21:49 20 Jun '07  
GeneralPlease Inform me PinmemberPrapthi0:17 26 Mar '07  
GeneralGiving ERROR menu is undefined Pinmemberswapnali.mankar1:45 16 Mar '07  
GeneralRe: Giving ERROR menu is undefined PinmemberAndré FliP10:28 19 Apr '07  
GeneralTigra Menu Pinmembertreputt7:16 2 Mar '07  
Questionneed object in menu.js 78 [modified] Pinmemberhihba16:42 6 Feb '07  
Joketanx PinmemberJuan Carlos Guillén Zurita6:43 2 Feb '07  
GeneralI don't see anything either. PinmemberGrondal2:03 17 Nov '06  
GeneralDont see anything... Pinmemberkeng150918:05 9 Nov '06  
GeneralVertical Menu Pinmembercsgraham10:23 17 Oct '06  
Generaljust want to said thank you Pinmembertarikelmallah10:45 16 Oct '06  
GeneralUsing different images for each menu? Pinmembersaeed_amd23:34 20 Sep '06  
GeneralHow to position the menu inside a table cell Pinmemberreza55315:36 1 Sep '06  
AnswerRe: How to position the menu inside a table cell PinmemberKountree11:00 9 Oct '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Sep 2005
Editor: Smitha Vijayan
Copyright 2005 by Krishna_accent
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project