Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Custom Controls Within Custom Controls

Status
Not open for further replies.

mateobus

Programmer
Aug 20, 2007
28
US
Hello, I am trying to create a custom control for creating tabs. The idea is that our designer can just use the control tags to generate the tabs. The problem that I am running into is that I want to be able to have a custom control that allows any number of child custom controls. So there would be a TabContainer Control, and within that there would be any number of tabs. The idea is similar to how an asp:DropDown list can have any number of ListItems within them. Here is my code, any help is appreciated.

1 <!-- TAB CONTAINER -->
2 <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TabContainer.ascx.vb" Inherits="CustomControls_TabContainer" %>
3 <div>
4
5 <ul class="tabs">
6 <asp:placeHolder ID="ph_list_items">
7
8 </asp:placeHolder>
9 </ul>
10
11 </div>
12
13 <!-- INDIVIDUAL TABS -->
14 <%@ Control Language="VB" AutoEventWireup="false" CodeFile="Tab.ascx.vb" Inherits="CustomControls_Tab" %>
15 <li>
16 <asp:HyperLink ID="hp_link" runat="server" />
17 </li>
18
19 <!-- PAGE SOURCE -->
20 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
21 <%@ Register
22 TagPrefix="uc"
23 TagName="TabContainer"
24 src="~\CustomControls\TabContainer.ascx" %>
25 <%@ Register
26 TagPrefix="uc"
27 TagName="Tab"
28 src="~\CustomControls\Tab.ascx" %>
29
30 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "31
32 <html xmlns="33 <head runat="server">
34 </head>
35 <body>
36 <form id="form1" runat="server">
37 <div>
38
39 <uc:TabContainer ID="tabs1" runat="server" IncludeArrows="True">
40 <uc:Tab ID="tab1" runat="server" LinkText="Tab1" LinkURL=" />
41 <uc:Tab ID="tab2" runat="server" LinkText="Tab1" LinkURL=" />
42 <uc:Tab ID="tab3" runat="server" LinkText="Tab1" LinkURL=" />
43 </uc:TabContainer>
44 </div>
45 </form>
46 </body>
47 </html>

For simplicity's sake I have left out the codebehind.
 
I don't understand the question. You want to create an arbitrary number of controls at runtime? You can always add them programatically.

dim myChild as ctlChild

myChild = new ctlChild()
myParent.Controls.Add(myChild)

The trick with that is to make sure you get you ID properties right so postbacks work.

Brian Begy
Chief Database Guy
Chicago Data Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top