• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Creating a custom web control that uses nested tags

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">
     <Buttons>
           <cc:Button id="topNavButton1">
                 <SubButtons>
                      <cc:Button id="subNav_1a"></cc:Button>
                      <cc:Button id="subNav_1b"></cc:Button>
                      <cc:Button id="subNav_1c"></cc:Button>
                 </SubButtons>
           </cc:Button>
           <cc:Button id="topNavButton2">
                 <SubButtons>
                      <cc:Button id="subNav_2a"></cc:Button>
                      <cc:Button id="subNav_2b"></cc:Button>
                      <cc:Button id="subNav_2c"></cc:Button>
                 </SubButtons>
           </cc:Button>
     </Buttons>
</cc:myNav>

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.
0
smooga
Asked:
smooga
  • 3
  • 2
1 Solution
 
smoogaAuthor Commented:
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?
0
 
smoogaAuthor Commented:
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!
0
 
raterusCommented:
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,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIITemplateClassInstantiateInTopic.asp

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!
--Michael
0
 
raterusCommented:
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now