ASP.NET
  Home arrow ASP.NET arrow Page 4 - Create a Simple, Cross-Browser, Dropdown M...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Create a Simple, Cross-Browser, Dropdown Menu User Control with C#
By: Wrox Team
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 109
    2002-11-05

    Table of Contents:
  • Create a Simple, Cross-Browser, Dropdown Menu User Control with C#
  • What are ASP.NET User Controls?
  • Control Design
  • Using the Control
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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" %>
    <html>
    <head><title>Horizontal Dropdown Menu</title></head>
    <body>
    <form id="Form1" method="post" runat="server">
    <myControls:Menu
    id="MenuControl1"
    runat="server"
    XmlFileName="menu.xml"
    XslFileName="menu.xsl"
    />
    </form>
    </body>
    </html>


    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

    More ASP.NET Articles
    More By Wrox Team


     

    ASP.NET ARTICLES

    - 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







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway