Page lifecycle and dynamic controls

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

    Page lifecycle and dynamic controls

    Hi,

    Is there good information about the asp.net page lifecycle in
    combination with dynamically loaded controls? Or on "how to build
    dynamic controls"? I keep hitting problems where values are not
    available at the moment I need them.

    Current problem:
    In a dynamically loaded ascx there is a dropdown. Based on the selected
    value (reloading an existing value or responding to a
    SelectedIndexCh anged event), I create a set of "property edit"
    controls. But when I try to save all selected values, the dropdowns in
    there (my dropdowns, based on existing dropdowns) sometimes come up
    empty.
    This happens especially the first time, so when the property controls
    are built following a SelectedIndexCh anged.

    Any suggestions?

    Hans Kesting


  • Mike Gleason jr Couturier

    #2
    Re: Page lifecycle and dynamic controls


    "Hans Kesting" <news.hansdk@sp amgourmet.coma écrit dans le message de
    news: ut$BNOZPJHA.356 0@TK2MSFTNGP02. phx.gbl...
    Hi,
    >
    Is there good information about the asp.net page lifecycle in combination
    with dynamically loaded controls? Or on "how to build dynamic controls"? I
    keep hitting problems where values are not available at the moment I need
    them.
    >
    Current problem:
    In a dynamically loaded ascx there is a dropdown. Based on the selected
    value (reloading an existing value or responding to a SelectedIndexCh anged
    event), I create a set of "property edit" controls. But when I try to save
    all selected values, the dropdowns in there (my dropdowns, based on
    existing dropdowns) sometimes come up empty.
    This happens especially the first time, so when the property controls are
    built following a SelectedIndexCh anged.
    >
    Any suggestions?
    >
    Hans Kesting
    >
    I don't know about you particular problem but you have to recreate everytime
    your dynamic controls in your Page Init function. Still in the init function
    you can set you control's content the first time the page loads
    (!IsPostBack).

    Subsequent page loads, the viewstate will kicks in but still, you have to
    re-create you dynamic control every page loads (even on postbacks).

    Hope it helps


    Comment

    • Hans Kesting

      #3
      Re: Page lifecycle and dynamic controls

      Mike Gleason jr Couturier was thinking very hard :
      "Hans Kesting" <news.hansdk@sp amgourmet.coma écrit dans le message de news:
      ut$BNOZPJHA.356 0@TK2MSFTNGP02. phx.gbl...
      >Hi,
      >>
      >Is there good information about the asp.net page lifecycle in combination
      >with dynamically loaded controls? Or on "how to build dynamic controls"? I
      >keep hitting problems where values are not available at the moment I need
      >them.
      >>
      >Current problem:
      >In a dynamically loaded ascx there is a dropdown. Based on the selected
      >value (reloading an existing value or responding to a SelectedIndexCh anged
      >event), I create a set of "property edit" controls. But when I try to save
      >all selected values, the dropdowns in there (my dropdowns, based on
      >existing dropdowns) sometimes come up empty.
      >This happens especially the first time, so when the property controls are
      >built following a SelectedIndexCh anged.
      >>
      >Any suggestions?
      >>
      >Hans Kesting
      >>
      >
      I don't know about you particular problem but you have to recreate everytime
      your dynamic controls in your Page Init function. Still in the init function
      you can set you control's content the first time the page loads
      (!IsPostBack).
      >
      Subsequent page loads, the viewstate will kicks in but still, you have to
      re-create you dynamic control every page loads (even on postbacks).
      >
      Hope it helps
      But if I should create everything in Page_Init, how can I respond to an
      IndexChanged event, which doesn't happen until *after* Page_Load?
      I know I should rebuild the controls every time. One of my problems is
      that I the information I need to decide *what* to (re)build isn't
      available yet at the time I should do it.

      And an additional question: does Ajax change that lifecycle? (the
      pulldown and the properties section ar in an UpdatePanel).

      Hans Kesting


      Comment

      • Mike Gleason jr Couturier

        #4
        Re: Page lifecycle and dynamic controls


        "Hans Kesting" <news.hansdk@sp amgourmet.coma écrit dans le message de
        news: %23b7tMvcPJHA.4 900@TK2MSFTNGP0 2.phx.gbl...
        Mike Gleason jr Couturier was thinking very hard :
        >"Hans Kesting" <news.hansdk@sp amgourmet.coma écrit dans le message de
        >news: ut$BNOZPJHA.356 0@TK2MSFTNGP02. phx.gbl...
        >>Hi,
        >>>
        >>Is there good information about the asp.net page lifecycle in
        >>combination with dynamically loaded controls? Or on "how to build
        >>dynamic controls"? I keep hitting problems where values are not
        >>available at the moment I need them.
        >>>
        >>Current problem:
        >>In a dynamically loaded ascx there is a dropdown. Based on the selected
        >>value (reloading an existing value or responding to a
        >>SelectedIndex Changed event), I create a set of "property edit" controls.
        >>But when I try to save all selected values, the dropdowns in there (my
        >>dropdowns, based on existing dropdowns) sometimes come up empty.
        >>This happens especially the first time, so when the property controls
        >>are built following a SelectedIndexCh anged.
        >>>
        >>Any suggestions?
        >>>
        >>Hans Kesting
        >>>
        >>
        >I don't know about you particular problem but you have to recreate
        >everytime your dynamic controls in your Page Init function. Still in the
        >init function you can set you control's content the first time the page
        >loads (!IsPostBack).
        >>
        >Subsequent page loads, the viewstate will kicks in but still, you have to
        >re-create you dynamic control every page loads (even on postbacks).
        >>
        >Hope it helps
        >
        But if I should create everything in Page_Init, how can I respond to an
        IndexChanged event, which doesn't happen until *after* Page_Load?
        I know I should rebuild the controls every time. One of my problems is
        that I the information I need to decide *what* to (re)build isn't
        available yet at the time I should do it.
        >
        And an additional question: does Ajax change that lifecycle? (the pulldown
        and the properties section ar in an UpdatePanel).
        >
        Hans Kesting
        >
        >
        I see.. for the event part you can (after creating it dynamically):

        MyDynamicContro l.OnIndexChange d += new [Handler]

        Mike


        Comment

        • Hans Kesting

          #5
          Re: Page lifecycle and dynamic controls

          Mike Gleason jr Couturier presented the following explanation :
          "Hans Kesting" <news.hansdk@sp amgourmet.coma écrit dans le message de news:
          %23b7tMvcPJHA.4 900@TK2MSFTNGP0 2.phx.gbl...
          >Mike Gleason jr Couturier was thinking very hard :
          >>"Hans Kesting" <news.hansdk@sp amgourmet.coma écrit dans le message de
          >>news: ut$BNOZPJHA.356 0@TK2MSFTNGP02. phx.gbl...
          >>>Hi,
          >>>>
          >>>Is there good information about the asp.net page lifecycle in combination
          >>>with dynamically loaded controls? Or on "how to build dynamic controls"?
          >>>I keep hitting problems where values are not available at the moment I
          >>>need them.
          >>>>
          >>>Current problem:
          >>>In a dynamically loaded ascx there is a dropdown. Based on the selected
          >>>value (reloading an existing value or responding to a
          >>>SelectedInde xChanged event), I create a set of "property edit" controls.
          >>>But when I try to save all selected values, the dropdowns in there (my
          >>>dropdowns, based on existing dropdowns) sometimes come up empty.
          >>>This happens especially the first time, so when the property controls are
          >>>built following a SelectedIndexCh anged.
          >>>>
          >>>Any suggestions?
          >>>>
          >>>Hans Kesting
          >>>>
          >>>
          >>I don't know about you particular problem but you have to recreate
          >>everytime your dynamic controls in your Page Init function. Still in the
          >>init function you can set you control's content the first time the page
          >>loads (!IsPostBack).
          >>>
          >>Subsequent page loads, the viewstate will kicks in but still, you have to
          >>re-create you dynamic control every page loads (even on postbacks).
          >>>
          >>Hope it helps
          >>
          >But if I should create everything in Page_Init, how can I respond to an
          >IndexChanged event, which doesn't happen until *after* Page_Load?
          >I know I should rebuild the controls every time. One of my problems is that
          >I the information I need to decide *what* to (re)build isn't available yet
          >at the time I should do it.
          >>
          >And an additional question: does Ajax change that lifecycle? (the pulldown
          >and the properties section ar in an UpdatePanel).
          >>
          >Hans Kesting
          >>
          >>
          >
          I see.. for the event part you can (after creating it dynamically):
          >
          MyDynamicContro l.OnIndexChange d += new [Handler]
          >
          Mike
          I know. The event does fire, my handler gets executed and adds the
          'property' fields to the page, so the page looks OK. However when I
          then hit the "save" button (after selecting values in the dropdowns of
          some properties) those values are lost.
          When I revisit the item, the dropdown is filled before the Load and the
          property-section is created in the Load event. Now the values in the
          property-pulldowns are saved correctly.

          So how can I get the property-section to behave correctly after an
          "index changed"?


          Hans Kesting


          Comment

          • Mike Gleason jr Couturier

            #6
            Re: Page lifecycle and dynamic controls

            Maybe Instead of adding dynamic controls in the event handler (selected
            index changed), you can create your dynamic controls in the page Init
            function when the selected index is discovered:

            You can check if the selected index changed by looking at those in you page
            Init:

            HttpContext.Cur rent.Request.Fo rm["__EVENTTAR GET"]
            HttpContext.Cur rent.Request.Fo rm["__EVENTARGUMEN T"]

            Mike



            Comment

            Working...