S
shapper
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
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