Property missing value

Discussion in 'ASP .Net' started by shapper, Feb 25, 2008.

  1. shapper

    shapper Guest

    Hello,

    I have a control with 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

    FormSection is another custom control. My control inherits from
    CompositeControl and I implement it as follows:

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

    Finally I need to run a method from a child control in each section
    when a Bubble event is caught:

    Protected Overrides Function OnBubbleEvent(ByVal source As Object,
    ByVal e As EventArgs) As Boolean

    If TypeOf e Is CommandEventArgs Then

    For Each section In Me.Sections
    For Each field In section.Fields
    If Not field.Validate Then

    ' Stop bubbling for EventArgs
    Return True

    End If
    Next field
    Next section
    OnCommand(e)

    End If

    ' Let bubbling run for non CommandEventArgs
    Return False

    End Function

    The problem is that Me.Sections has no section in it so the loop does
    not run.

    But the sections are there! I added them and when I run the page I see
    all them.

    What am I doing wrong?

    Thanks,

    Miguel
    shapper, Feb 25, 2008
    #1
    1. Advertising

  2. The OnBubbleEvent method is called prior to the CreateChildControls method
    in the Control lifecycle.

    --
    HTH,

    Kevin Spencer
    Chicken Salad Surgeon
    Microsoft MVP

    "shapper" <> wrote in message
    news:...
    > Hello,
    >
    > I have a control with 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
    >
    > FormSection is another custom control. My control inherits from
    > CompositeControl and I implement it as follows:
    >
    > Protected Overrides Sub CreateChildControls()
    > For Each section As FormSection In Me.Sections
    > MyBase.Controls.Add(section)
    > Next
    > MyBase.CreateChildControls()
    > End Sub
    >
    > Finally I need to run a method from a child control in each section
    > when a Bubble event is caught:
    >
    > Protected Overrides Function OnBubbleEvent(ByVal source As Object,
    > ByVal e As EventArgs) As Boolean
    >
    > If TypeOf e Is CommandEventArgs Then
    >
    > For Each section In Me.Sections
    > For Each field In section.Fields
    > If Not field.Validate Then
    >
    > ' Stop bubbling for EventArgs
    > Return True
    >
    > End If
    > Next field
    > Next section
    > OnCommand(e)
    >
    > End If
    >
    > ' Let bubbling run for non CommandEventArgs
    > Return False
    >
    > End Function
    >
    > The problem is that Me.Sections has no section in it so the loop does
    > not run.
    >
    > But the sections are there! I added them and when I run the page I see
    > all them.
    >
    > What am I doing wrong?
    >
    > Thanks,
    >
    > Miguel
    Kevin Spencer, Feb 25, 2008
    #2
    1. Advertising

  3. shapper

    shapper Guest

    On Feb 25, 11:41 am, "Kevin Spencer" <unclechutney@localhost> wrote:
    > The OnBubbleEvent method is called prior to the CreateChildControls method
    > in the Control lifecycle.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Chicken Salad Surgeon
    > Microsoft MVP
    >
    > "shapper" <> wrote in message
    >
    > news:...
    >
    > > Hello,

    >
    > > I have a control with 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

    >
    > > FormSection is another custom control. My control inherits from
    > > CompositeControl and I implement it as follows:

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

    >
    > > Finally I need to run a method from a child control in each section
    > > when a Bubble event is caught:

    >
    > > Protected Overrides Function OnBubbleEvent(ByVal source As Object,
    > > ByVal e As EventArgs) As Boolean

    >
    > > If TypeOf e Is CommandEventArgs Then

    >
    > > For Each section In Me.Sections
    > > For Each field In section.Fields
    > > If Not field.Validate Then

    >
    > > ' Stop bubbling for EventArgs
    > > Return True

    >
    > > End If
    > > Next field
    > > Next section
    > > OnCommand(e)

    >
    > > End If

    >
    > > ' Let bubbling run for non CommandEventArgs
    > > Return False

    >
    > > End Function

    >
    > > The problem is that Me.Sections has no section in it so the loop does
    > > not run.

    >
    > > But the sections are there! I added them and when I run the page I see
    > > all them.

    >
    > > What am I doing wrong?

    >
    > > Thanks,

    >
    > > Miguel


    So there is no solution to this?
    How is this usually done? Any idea?

    Basically, I need to stop the event if the Section controls do not
    validate ...

    Thanks,
    Miguel
    shapper, Feb 25, 2008
    #3
  4. shapper

    bruce barker Guest

    in OnBubbleEvent, before accessing any child controls, call
    EnsureChildControls().

    -- bruce (sqlwork.com)


    "shapper" wrote:

    > On Feb 25, 11:41 am, "Kevin Spencer" <unclechutney@localhost> wrote:
    > > The OnBubbleEvent method is called prior to the CreateChildControls method
    > > in the Control lifecycle.
    > >
    > > --
    > > HTH,
    > >
    > > Kevin Spencer
    > > Chicken Salad Surgeon
    > > Microsoft MVP
    > >
    > > "shapper" <> wrote in message
    > >
    > > news:...
    > >
    > > > Hello,

    > >
    > > > I have a control with 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

    > >
    > > > FormSection is another custom control. My control inherits from
    > > > CompositeControl and I implement it as follows:

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

    > >
    > > > Finally I need to run a method from a child control in each section
    > > > when a Bubble event is caught:

    > >
    > > > Protected Overrides Function OnBubbleEvent(ByVal source As Object,
    > > > ByVal e As EventArgs) As Boolean

    > >
    > > > If TypeOf e Is CommandEventArgs Then

    > >
    > > > For Each section In Me.Sections
    > > > For Each field In section.Fields
    > > > If Not field.Validate Then

    > >
    > > > ' Stop bubbling for EventArgs
    > > > Return True

    > >
    > > > End If
    > > > Next field
    > > > Next section
    > > > OnCommand(e)

    > >
    > > > End If

    > >
    > > > ' Let bubbling run for non CommandEventArgs
    > > > Return False

    > >
    > > > End Function

    > >
    > > > The problem is that Me.Sections has no section in it so the loop does
    > > > not run.

    > >
    > > > But the sections are there! I added them and when I run the page I see
    > > > all them.

    > >
    > > > What am I doing wrong?

    > >
    > > > Thanks,

    > >
    > > > Miguel

    >
    > So there is no solution to this?
    > How is this usually done? Any idea?
    >
    > Basically, I need to stop the event if the Section controls do not
    > validate ...
    >
    > Thanks,
    > Miguel
    >
    bruce barker, Feb 25, 2008
    #4
  5. shapper

    shapper Guest

    On Feb 25, 4:44 pm, bruce barker
    <> wrote:
    > in OnBubbleEvent, before accessing any child controls, call
    > EnsureChildControls().
    >
    > -- bruce (sqlwork.com)
    >
    > "shapper" wrote:
    > > On Feb 25, 11:41 am, "Kevin Spencer" <unclechutney@localhost> wrote:
    > > > The OnBubbleEvent method is called prior to the CreateChildControls method
    > > > in the Control lifecycle.

    >
    > > > --
    > > > HTH,

    >
    > > > Kevin Spencer
    > > > Chicken Salad Surgeon
    > > > Microsoft MVP

    >
    > > > "shapper" <> wrote in message

    >
    > > >news:...

    >
    > > > > Hello,

    >
    > > > > I have a control with 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

    >
    > > > > FormSection is another custom control. My control inherits from
    > > > > CompositeControl and I implement it as follows:

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

    >
    > > > > Finally I need to run a method from a child control in each section
    > > > > when a Bubble event is caught:

    >
    > > > > Protected Overrides Function OnBubbleEvent(ByVal source As Object,
    > > > > ByVal e As EventArgs) As Boolean

    >
    > > > > If TypeOf e Is CommandEventArgs Then

    >
    > > > > For Each section In Me.Sections
    > > > > For Each field In section.Fields
    > > > > If Not field.Validate Then

    >
    > > > > ' Stop bubbling for EventArgs
    > > > > Return True

    >
    > > > > End If
    > > > > Next field
    > > > > Next section
    > > > > OnCommand(e)

    >
    > > > > End If

    >
    > > > > ' Let bubbling run for non CommandEventArgs
    > > > > Return False

    >
    > > > > End Function

    >
    > > > > The problem is that Me.Sections has no section in it so the loop does
    > > > > not run.

    >
    > > > > But the sections are there! I added them and when I run the page I see
    > > > > all them.

    >
    > > > > What am I doing wrong?

    >
    > > > > Thanks,

    >
    > > > > Miguel

    >
    > > So there is no solution to this?
    > > How is this usually done? Any idea?

    >
    > > Basically, I need to stop the event if the Section controls do not
    > > validate ...

    >
    > > Thanks,
    > > Miguel


    I tried but it does not work.

    Any idea?

    Thanks,
    Miguel
    shapper, Feb 27, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary Herron
    Replies:
    2
    Views:
    663
    Bruno Desthuilliers
    Jul 4, 2006
  2. Nathan Sokalski
    Replies:
    25
    Views:
    1,426
    Nathan Sokalski
    Mar 4, 2010
  3. Dev_SH
    Replies:
    0
    Views:
    657
    Dev_SH
    Dec 30, 2010
  4. KJ
    Replies:
    0
    Views:
    144
  5. Matt Kruse
    Replies:
    4
    Views:
    125
    Elegie
    Jan 8, 2007
Loading...

Share This Page