473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1310
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 important to note that the user control that hosts...
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 webforms, a user control, and a module: ...
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 Designer Generated Code" section. Every time an...
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 it simply when I code on form.vb, but when go to...
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 some actions on several form controls that have...
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 boolean: DefaultValue(true) DefaultValue("true")...
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 is that the panel on my custom control doesnt...
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. Reads the file. Executes the program specified in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.