Property is empty. Why?

S

shapper

Hello,

I am creating a custom control, named Form, which inherits from
CompositeControl.

I am adding child custom controls, named Section, to the Form through
the following property:

Private _Sections As New List(Of FormSection)
Public Property Sections() As List(Of FormSection)
Get
If _Sections Is Nothing Then
_Sections = New List(Of FormSection)
End If
Return _Sections
End Get
Set(ByVal value As List(Of FormSection))
_Sections = value
End Set
End Property ' Sections

Then I build my control as follows:

Protected Overrides Sub CreateChildControls()
For Each section As FormSection In Me.Sections
MyBase.Controls.Add(section)
Next ' section
MyBase.CreateChildControls()
End Sub

However, in OnBubbleEvent, which I am overriding, Me.Sections count 0
while Me.Controls count 4, the number of controls I added:

Protected Overrides Function OnBubbleEvent(ByVal source As Object,
ByVal e As EventArgs) As Boolean
Dim c As ControlCollection = Me.Controls
Dim s As List(Of FormSection) = Me.Sections
End sub

Why?

I was using a Loop with Me.Sections and it was not working and now I
found out why.

What am I doing wrong?

Thanks,

Miguel
 
B

bruce barker

when do you ever add a section to the control? do you do it on postback?

-- bruce (sqlwork.com)
 
S

shapper

when do you ever add a section to the control? do you do it on postback?

-- bruce (sqlwork.com)

I do it on Page_Init when I am adding controls to the page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top