Property missing value

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

    Property missing value

    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
    CompositeContro l and I implement it as follows:

    Protected Overrides Sub CreateChildCont rols()
    For Each section As FormSection In Me.Sections
    MyBase.Controls .Add(section)
    Next
    MyBase.CreateCh ildControls()
    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(B yVal source As Object,
    ByVal e As EventArgs) As Boolean

    If TypeOf e Is CommandEventArg s 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 CommandEventArg s
    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

    #2
    Re: Property missing value

    The OnBubbleEvent method is called prior to the CreateChildCont rols method
    in the Control lifecycle.

    --
    HTH,

    Kevin Spencer
    Chicken Salad Surgeon
    Microsoft MVP

    "shapper" <mdmoura@gmail. comwrote in message
    news:c64ea088-46d0-46a4-8d7d-c6483ad47c22@n7 7g2000hse.googl egroups.com...
    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
    CompositeContro l and I implement it as follows:
    >
    Protected Overrides Sub CreateChildCont rols()
    For Each section As FormSection In Me.Sections
    MyBase.Controls .Add(section)
    Next
    MyBase.CreateCh ildControls()
    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(B yVal source As Object,
    ByVal e As EventArgs) As Boolean
    >
    If TypeOf e Is CommandEventArg s 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 CommandEventArg s
    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

    Comment

    • shapper

      #3
      Re: Property missing value

      On Feb 25, 11:41 am, "Kevin Spencer" <unclechutney@l ocalhostwrote:
      The OnBubbleEvent method is called prior to the CreateChildCont rols method
      in the Control lifecycle.
      >
      --
      HTH,
      >
      Kevin Spencer
      Chicken Salad Surgeon
      Microsoft MVP
      >
      "shapper" <mdmo...@gmail. comwrote in message
      >
      news:c64ea088-46d0-46a4-8d7d-c6483ad47c22@n7 7g2000hse.googl egroups.com...
      >
      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
      CompositeContro l and I implement it as follows:
      >
      Protected Overrides Sub CreateChildCont rols()
      For Each section As FormSection In Me.Sections
      MyBase.Controls .Add(section)
      Next
      MyBase.CreateCh ildControls()
      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(B yVal source As Object,
      ByVal e As EventArgs) As Boolean
      >
      If TypeOf e Is CommandEventArg s 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 CommandEventArg s
      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

      Comment

      • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

        #4
        Re: Property missing value

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

        -- bruce (sqlwork.com)


        "shapper" wrote:
        On Feb 25, 11:41 am, "Kevin Spencer" <unclechutney@l ocalhostwrote:
        The OnBubbleEvent method is called prior to the CreateChildCont rols method
        in the Control lifecycle.

        --
        HTH,

        Kevin Spencer
        Chicken Salad Surgeon
        Microsoft MVP

        "shapper" <mdmo...@gmail. comwrote in message

        news:c64ea088-46d0-46a4-8d7d-c6483ad47c22@n7 7g2000hse.googl egroups.com...
        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
        CompositeContro l and I implement it as follows:
        Protected Overrides Sub CreateChildCont rols()
        For Each section As FormSection In Me.Sections
        MyBase.Controls .Add(section)
        Next
        MyBase.CreateCh ildControls()
        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(B yVal source As Object,
        ByVal e As EventArgs) As Boolean
        If TypeOf e Is CommandEventArg s 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 CommandEventArg s
        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
        >

        Comment

        • shapper

          #5
          Re: Property missing value

          On Feb 25, 4:44 pm, bruce barker
          <brucebar...@di scussions.micro soft.comwrote:
          in OnBubbleEvent, before accessing any child controls, call
          EnsureChildCont rols().
          >
          -- bruce (sqlwork.com)
          >
          "shapper" wrote:
          On Feb 25, 11:41 am, "Kevin Spencer" <unclechutney@l ocalhostwrote:
          The OnBubbleEvent method is called prior to the CreateChildCont rols method
          in the Control lifecycle.
          >
          --
          HTH,
          >
          Kevin Spencer
          Chicken Salad Surgeon
          Microsoft MVP
          >
          "shapper" <mdmo...@gmail. comwrote in message
          >
          >news:c64ea08 8-46d0-46a4-8d7d-c6483ad47c22@n7 7g2000hse.googl egroups.com...
          >
          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
          CompositeContro l and I implement it as follows:
          >
          Protected Overrides Sub CreateChildCont rols()
          For Each section As FormSection In Me.Sections
          MyBase.Controls .Add(section)
          Next
          MyBase.CreateCh ildControls()
          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(B yVal source As Object,
          ByVal e As EventArgs) As Boolean
          >
          If TypeOf e Is CommandEventArg s 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 CommandEventArg s
          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

          Comment

          Working...