Creating a custom web control that uses nested tags

Posted on 2005-04-28
Last Modified: 2006-11-18
I am trying to create a reusable navigation bar as a web control.  I would like to be able to add buttons to the nav in the following manner:

<cc:MyNav id="myNav" runat="server">
           <cc:Button id="topNavButton1">
                      <cc:Button id="subNav_1a"></cc:Button>
                      <cc:Button id="subNav_1b"></cc:Button>
                      <cc:Button id="subNav_1c"></cc:Button>
           <cc:Button id="topNavButton2">
                      <cc:Button id="subNav_2a"></cc:Button>
                      <cc:Button id="subNav_2b"></cc:Button>
                      <cc:Button id="subNav_2c"></cc:Button>

So, this would give me a navbar with two buttons that each have 3 subnav buttons.  It is similar to the DataGrid which has the "Columns" tag that you can define your columns in.  My question is, how do I set up a Custom Control like this?  How would I set up the "<Buttons>" and "<SubButtons>" functionality?  Ideally, I'd like to have a method that is called to handle each item under <Buttons> and <SubButtons>.  I haven't been able to find any examples of this.
Question by:smooga
    LVL 33

    Expert Comment


    Author Comment

    Thanks for the link... I don't quite understand how to implement this though.

    By just playing around I've discovered that if I create a public "Buttons" 'set' property, it gets called each time "<Buttons>" is defined in the aspx page.  When this is called, can I access the Button objects defined between the Buttons tag?  Is there a way to enumerate through the Buttons collection here?

    Accepted Solution

    Ok, figured it out.  You can just enumerate through the property value.  In C# I'm using:

    set {
          foreach ( Button b in value ) {
                // do stuff

    I guess it's passing an ArrayList of the buttons.  Just what I wanted!
    LVL 33

    Expert Comment

    The concept is achieved through ITemplates, I'm sorry I can't be more of a help, I've never really done this, just know how it is done.

    You'll need to use this method too,

    Sorry, been looking for a good example to show you, unfortunately this is a pretty advanced technique, and examples are apparently hard to come by!
    LVL 33

    Expert Comment

    Hey if it works go for it!, but if you wanted a challenge I'd look into ITemplates, it is the "correct" way to do it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now