472,353 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Control / Property. Going crazy here.

Hello,

I have a class where I created various controls.
One of the controls have a property which is a generic list of
WebControl.

Then in web site page I have something like:
Dim a As New MyNamespace.ListItem
a.WebControls.Add(tbName)
a.WebControls.Add(lLabel)
Response.Write(a.WebControls.Count) >>This returns 0!

When the control renders I can only see its start and end tags.
The controls that I added to it are not rendered into the page.
In fact they seem to not being added to the WebControls property.
(Count returns 0)

I am on this for 2 days. I have no idea what is going on. I tried
everything I could think of!
I think the problem might be in my control property WebControls.

Please, could someone help me out?

Here is my control code:

<DefaultProperty("ID"), ToolboxData("<{0}:Item runat=server></
{0}:Item>")_
Public Class ListItem
Inherits WebControl
Implements INamingContainer

<Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)_
Property WebControls() As Generic.List(Of WebControl)
Get
If CStr(ViewState("WebControls")) Is Nothing Then
Return New Generic.List(Of WebControl)
Else
Return ViewState("WebControls")
End If
End Get
Set(ByVal Value As Generic.List(Of WebControl))
ViewState("WebControls") = Value
End Set
End Property ' WebControls

' CreateChildControls
Protected Overrides Sub CreateChildControls()

' Add controls to item
For Each control As WebControl In Me.WebControls
MyBase.Controls.Add(control)
Next ' control

' Create child controls
MyBase.CreateChildControls()
Me.ChildControlsCreated = True

End Sub ' CreateChildControls

End Class ' List

Thanks,
Miguel

May 28 '07 #1
1 1251
On May 28, 7:38 pm, shapper <mdmo...@gmail.comwrote:
Hello,

I have a class where I created various controls.
One of the controls have a property which is a generic list of
WebControl.

Then in web site page I have something like:
Dim a As New MyNamespace.ListItem
a.WebControls.Add(tbName)
a.WebControls.Add(lLabel)
Response.Write(a.WebControls.Count) >>This returns 0!

When the control renders I can only see its start and end tags.
The controls that I added to it are not rendered into the page.
In fact they seem to not being added to the WebControls property.
(Count returns 0)

I am on this for 2 days. I have no idea what is going on. I tried
everything I could think of!
I think the problem might be in my control property WebControls.

Please, could someone help me out?

Here is my control code:

<DefaultProperty("ID"), ToolboxData("<{0}:Item runat=server></
{0}:Item>")_
Public Class ListItem
Inherits WebControl
Implements INamingContainer

<Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)_
Property WebControls() As Generic.List(Of WebControl)
Get
If CStr(ViewState("WebControls")) Is Nothing Then
Return New Generic.List(Of WebControl)
Else
Return ViewState("WebControls")
End If
End Get
Set(ByVal Value As Generic.List(Of WebControl))
ViewState("WebControls") = Value
End Set
End Property ' WebControls

' CreateChildControls
Protected Overrides Sub CreateChildControls()

' Add controls to item
For Each control As WebControl In Me.WebControls
MyBase.Controls.Add(control)
Next ' control

' Create child controls
MyBase.CreateChildControls()
Me.ChildControlsCreated = True

End Sub ' CreateChildControls

End Class ' List

Thanks,
Miguel
Please, anyone?

My full code is as follows:

1
2 <DefaultProperty("ID"), ToolboxData("<{0}:ListItem
runat=server></{0}:ListItem>")_
3 Public Class ListItem
4 Inherits WebControl
5 Implements INamingContainer
6
7 <Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)_
8 Property WebControls() As Generic.List(Of WebControl)
9 Get
10 If CStr(ViewState("WebControls")) Is Nothing Then
11 Return New Generic.List(Of WebControl)
12 Else
13 Return ViewState("WebControls")
14 End If
15 End Get
16 Set(ByVal Value As Generic.List(Of WebControl))
17 ViewState("WebControls") = Value
18 End Set
19 End Property ' WebControls
20
21 Protected Overrides Sub CreateChildControls()
22
23 ' Add controls to item
24 For Each control As WebControl In Me.WebControls
25 MyBase.Controls.Add(control)
26 Next ' control
27
28 ' Create child controls
29 MyBase.CreateChildControls()
30 Me.ChildControlsCreated = True
31
32 End Sub ' CreateChildControls
33 End Class ' ListItem
34
35 ' List
36 <DefaultProperty("ID"), ToolboxData("<{0}:List runat=server></
{0}:List>")_
37 Public Class List
38 Inherits WebControl
39 Implements INamingContainer
40
41 ' Items ...
42 <Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)_
43 Property Items() As Generic.List(Of ListItem)
44 Get
45 If CStr(ViewState("Items")) Is Nothing Then
46 Return New Generic.List(Of ListItem)
47 Else
48 Return ViewState("Items")
49 End If
50 End Get
51 Set(ByVal Value As Generic.List(Of ListItem))
52 ViewState("Item") = Value
53 End Set
54 End Property ' Items
55
56 ' CreateChildControls
57 Protected Overrides Sub CreateChildControls()
58
59 ' Add controls to item
60 For Each item As ListItem In Me.Items
61 MyBase.Controls.Add(item)
62 Next ' item
63
64 ' Create child controls
65 MyBase.CreateChildControls()
66 Me.ChildControlsCreated = True
67
68 End Sub ' CreateChildControls
69
70 End Class ' List
Thanks,
Miguel

May 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Smithers | last post by:
I have a non trivial ASP.NET Web application that implements its navigation system via a user control (menu.ascx) placed on every page. It is...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form...
3
by: Brent McIntyre | last post by:
Good evening all, I am going crazy with a problem that I am sure has a simple solution. I need to add items to a ComboBox on a Form. I can do...
7
by: BradC | last post by:
(VB.NET 2002, Windows app). I'm going to be provided a two-letter string like "BV" or "TP" that represents a location. I then need to perform...
6
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having...
0
by: sean worlock | last post by:
Hello all, I have googled like crazy for this with no sucess! I have a dataset containing a table with the following fields Table===Widths...
0
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file....
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.