Property is empty. Why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Property is empty. Why?

    Hello,

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

    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 CreateChildCont rols()
    For Each section As FormSection In Me.Sections
    MyBase.Controls .Add(section)
    Next ' section
    MyBase.CreateCh ildControls()
    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(B yVal source As Object,
    ByVal e As EventArgs) As Boolean
    Dim c As ControlCollecti on = 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
  • bruce barker

    #2
    Re: Property is empty. Why?

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

    -- bruce (sqlwork.com)

    shapper wrote:
    Hello,
    >
    I am creating a custom control, named Form, which inherits from
    CompositeContro l.
    >
    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 CreateChildCont rols()
    For Each section As FormSection In Me.Sections
    MyBase.Controls .Add(section)
    Next ' section
    MyBase.CreateCh ildControls()
    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(B yVal source As Object,
    ByVal e As EventArgs) As Boolean
    Dim c As ControlCollecti on = 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

    Comment

    • shapper

      #3
      Re: Property is empty. Why?

      On Feb 23, 7:43 pm, bruce barker <nos...@nospam. comwrote:
      when do you ever add a section to the control? do you do it on postback?
      >
      -- bruce (sqlwork.com)
      >
      shapper wrote:
      Hello,
      >
      I am creating a custom control, named Form, which inherits from
      CompositeContro l.
      >
      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 CreateChildCont rols()
      For Each section As FormSection In Me.Sections
      MyBase.Controls .Add(section)
      Next ' section
      MyBase.CreateCh ildControls()
      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(B yVal source As Object,
      ByVal e As EventArgs) As Boolean
      Dim c As ControlCollecti on = 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
      I do it on Page_Init when I am adding controls to the page.

      Comment

      Working...