Click here to Skip to main content
15,885,032 members
Articles / Web Development / ASP.NET

Custom Web Menu with Embedded Resources

Rate me:
Please Sign up or sign in to vote.
4.25/5 (4 votes)
30 Mar 2010CPOL2 min read 32.8K   912   17   1
This is a free custom web menu with Tigra menu (free JavaScript menu) embedded.
Image 1

Introduction

This is a free custom web menu with Tigra menu (free JavaScript menu) embedded. Menu creation and binding is dynamic. Data Source for the menu can be either an XML file or dataset filled from the DB. Menu styles can be easily overridden in the application that uses this menu using CSS. The menu supports various properties for customization. This custom article also explains how to embed resources in a custom control. The Custom web menu is a typical web menu that can be used in any web application.

Using the Code

Steps Involved in Setting the Project

  1. Download the projects.
  2. Set Default.aspx as “Set as start page”.
  3. Run the project.

Description

The control generates menu to n-depth dynamically at runtime. The data source to the menu can be either a .xml file or a dataset. The source can be set using the properties MenuXMLPath or DataSource for XML or dataset respectively.

C#
[Category("Appearance"),DefaultValue("")]
public string MenuXMLPath
{ 
    get{return xmlDataSource;} 
    set{xmlDataSource = value;} 
} 

/// <summary>
/// DataSet from the XML menu as DataSource. 
/// </summary>

[Bindable(true),Category("Appearance"),DefaultValue("")]
public DataSet DataSource 
{
 get{return dsMenu;}
 set{dsMenu = value;} 
}

This menu use the Tigra Menu JavaScript for dynamic menu creation and binding. The menu can extend to any depth. The datasource (XML file or DB table) to the control should be of the below schema:

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

To get the DLL, please run the project “CustomWebMenu".

Embedded Resource

Set the Build Action for the resource file as "Embedded Resource" from File->Properties->Build action.

Include the below code snippet in the AssemblyInfo.cs file:

C#
[assembly: WebResource("CustomWebMenu.Resources.CustomWebMenu.js", 
    "application/x-javascript")]

[assembly: WebResource("CustomWebMenu.Resources.Images.OneStep.gif", "image/gif")]

Points of Interest

There may be many menus available on the web. This differs from all of them in the way the resources to the Menu like JavaScript files, images, etc. are embedded with the CustomWebMenu.dll. You need not carry those resources to the projects where you are going to use the menu. You just need to refer the CustomWebMenu.dll.

Conclusion

Use the source code. Blend it with various new ideas. Feedbacks, suggestion and corrections are welcome. Enjoy coding.

The above code embeds the resource to the assembly. This prevents carrying these files to the project where the DLL is referenced.

History

  • 30th March, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
A C# lover....

Comments and Discussions

 
GeneralWeb Menu Pin
stixoffire5-Apr-10 18:45
stixoffire5-Apr-10 18:45 

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.