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.Lis tItem
a.WebControls.A dd(tbName)
a.WebControls.A dd(lLabel)
Response.Write( a.WebControls.C ount) >>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:
<DefaultPropert y("ID"), ToolboxData("<{ 0}:Item runat=server></
{0}:Item>")_
Public Class ListItem
Inherits WebControl
Implements INamingContaine r
<Bindable(True) , Category("Setti ngs"), DefaultValue("" ),
Localizable(Tru e)_
Property WebControls() As Generic.List(Of WebControl)
Get
If CStr(ViewState( "WebControl s")) Is Nothing Then
Return New Generic.List(Of WebControl)
Else
Return ViewState("WebC ontrols")
End If
End Get
Set(ByVal Value As Generic.List(Of WebControl))
ViewState("WebC ontrols") = Value
End Set
End Property ' WebControls
' CreateChildCont rols
Protected Overrides Sub CreateChildCont rols()
' Add controls to item
For Each control As WebControl In Me.WebControls
MyBase.Controls .Add(control)
Next ' control
' Create child controls
MyBase.CreateCh ildControls()
Me.ChildControl sCreated = True
End Sub ' CreateChildCont rols
End Class ' List
Thanks,
Miguel
Please, anyone?
My full code is as follows:
1
2 <DefaultPropert y("ID"), ToolboxData("<{ 0}:ListItem
runat=server></{0}:ListItem>") _
3 Public Class ListItem
4 Inherits WebControl
5 Implements INamingContaine r
6
7 <Bindable(True) , Category("Setti ngs"), DefaultValue("" ),
Localizable(Tru e)_
8 Property WebControls() As Generic.List(Of WebControl)
9 Get
10 If CStr(ViewState( "WebControl s")) Is Nothing Then
11 Return New Generic.List(Of WebControl)
12 Else
13 Return ViewState("WebC ontrols")
14 End If
15 End Get
16 Set(ByVal Value As Generic.List(Of WebControl))
17 ViewState("WebC ontrols") = Value
18 End Set
19 End Property ' WebControls
20
21 Protected Overrides Sub CreateChildCont rols()
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.CreateCh ildControls()
30 Me.ChildControl sCreated = True
31
32 End Sub ' CreateChildCont rols
33 End Class ' ListItem
34
35 ' List
36 <DefaultPropert y("ID"), ToolboxData("<{ 0}:List runat=server></
{0}:List>")_
37 Public Class List
38 Inherits WebControl
39 Implements INamingContaine r
40
41 ' Items ...
42 <Bindable(True) , Category("Setti ngs"), DefaultValue("" ),
Localizable(Tru e)_
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("Item s")
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 ' CreateChildCont rols
57 Protected Overrides Sub CreateChildCont rols()
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.CreateCh ildControls()
66 Me.ChildControl sCreated = True
67
68 End Sub ' CreateChildCont rols
69
70 End Class ' List
Thanks,
Miguel