Home arrow ASP.NET arrow Page 4 - Create a Simple, Cross-Browser, Dropdown Menu User Control with C#

Create a Simple, Cross-Browser, Dropdown Menu User Control with C#

In this article, Nick Howard will demonstrate the use of an ASP.NET user control coded in C#. In order to accomplish this task, a variety of technologies will be utilized including XML, XSL/XSLT, CSS and JavaScript.

Author Info:
By: Wrox Team
Rating: 4 stars4 stars4 stars4 stars4 stars / 158
November 05, 2002
  1. · Create a Simple, Cross-Browser, Dropdown Menu User Control with C#
  2. · What are ASP.NET User Controls?
  3. · Control Design
  4. · Using the Control
  5. · Conclusion

print this article

Create a Simple, Cross-Browser, Dropdown Menu User Control with C# - Using the Control
(Page 4 of 5 )

You need to complete a couple more tasks before you can use your new user control. First, place the control within a WebForm. In order to use the control within a WebForm, you must "register" the control so the parent form knows what to do when it sees this new, custom tag set in its page. ASP.NET enables this through the <@Register ... > directive tag. It is placed at the top of the WebForm.

<%@ Register TagPrefix="ASPToday" TagName="HMenu" Src="MenuControl.ascx" %>

The TagPrefix identifies the control (like the asp: prefix for Microsoft server controls). The TagName names the control so we know how to reference it in the page. The Src attribute points to the file that describes how the user control looks. To use the control in a WebForm, simply use the following syntax:

<ASPToday:HMenu runat="server" ... />

In addition to what you see in the previous line of code, any public variables that were declared as part of the user control can also be set with the attribute=value syntax. In our case, we have two such attributes - XmlFileName and XslFileName. The final .aspx page is as follows:

<%@ Register TagPrefix="myControls" TagName="Menu" Src="MenuControl.ascx" %>
<head><title>Horizontal Dropdown Menu</title></head>
<form id="Form1" method="post" runat="server">

Now you have everything you need to utilize the user control - the user control files (MenuControl.ascx and MenuControl.ascx.cs) and the .aspx file (named Test.aspx in the download). Create a virtual directory in IIS that points to the folder containing the user control files, test page and the XML, XSL, CSS and JavaScript files from the download. Load your test page into the browser and watch the menu appear. (Figure 2)

Figure 2 Horizontal Menu User Control as part of an ASP.NET WebForm
blog comments powered by Disqus

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials