Dynamic Controls in User Control; page/control lifecycle question

Discussion in 'ASP .Net' started by Frankie, Jun 22, 2005.

  1. Frankie

    Frankie Guest

    I have a user control into which I insert a bunch of controls dynamically. I
    have it all working just fine - Everything is there on Postback, etc.

    I load this user control into a hosting ASPX page at runtime during the
    Page_Load event procedure of the hosting ASPX page.

    Question: Would it be better to load the user control from the hosting
    page's OnInit event rather than Page_Load? Does it matter or not?

    I ask because I understand that for dynamic controls to be properly
    inserted - it must be done during the OnInit event - which is happening -
    but only in the ASCX lifecycle (which gets kicked off from the hosting aspx
    page_load).

    Thanks.
    Frankie, Jun 22, 2005
    #1
    1. Advertising

  2. Hi Frankie,

    The following >Net SDK article on Control Execution Lifecycle should clear
    everything up for you. I keep a print-out of it on my office wall!

    http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Ambiguity has a certain quality to it.

    "Frankie" <> wrote in message
    news:%...
    >I have a user control into which I insert a bunch of controls dynamically.
    >I have it all working just fine - Everything is there on Postback, etc.
    >
    > I load this user control into a hosting ASPX page at runtime during the
    > Page_Load event procedure of the hosting ASPX page.
    >
    > Question: Would it be better to load the user control from the hosting
    > page's OnInit event rather than Page_Load? Does it matter or not?
    >
    > I ask because I understand that for dynamic controls to be properly
    > inserted - it must be done during the OnInit event - which is happening -
    > but only in the ASCX lifecycle (which gets kicked off from the hosting
    > aspx page_load).
    >
    > Thanks.
    >
    Kevin Spencer, Jun 23, 2005
    #2
    1. Advertising

  3. Frankie

    Frankie Guest

    Thanks Keven - great little article. Based on the following statements in
    the article...

    "a control is unable to invoke its parent until the tree of controls on a
    page has been populated"
    and
    "CreateChildControls can be invoked when loading a page, during data
    binding, or during rendering"

    .... I'm concluding that the scenario I have created (as described in the OP)
    is just fine - if not what must happen. If I'm totally wrong about that,
    then please let me know - otherwise have a great day!

    -Frankie



    "Kevin Spencer" <> wrote in message
    news:eiEi2b%...
    > Hi Frankie,
    >
    > The following >Net SDK article on Control Execution Lifecycle should clear
    > everything up for you. I keep a print-out of it on my office wall!
    >
    > http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > Ambiguity has a certain quality to it.
    >
    > "Frankie" <> wrote in message
    > news:%...
    >>I have a user control into which I insert a bunch of controls dynamically.
    >>I have it all working just fine - Everything is there on Postback, etc.
    >>
    >> I load this user control into a hosting ASPX page at runtime during the
    >> Page_Load event procedure of the hosting ASPX page.
    >>
    >> Question: Would it be better to load the user control from the hosting
    >> page's OnInit event rather than Page_Load? Does it matter or not?
    >>
    >> I ask because I understand that for dynamic controls to be properly
    >> inserted - it must be done during the OnInit event - which is happening -
    >> but only in the ASCX lifecycle (which gets kicked off from the hosting
    >> aspx page_load).
    >>
    >> Thanks.
    >>

    >
    >
    Frankie, Jun 23, 2005
    #3
    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. Jonny

    User Controls Event Lifecycle

    Jonny, Sep 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    7,877
    Scott Allen
    Sep 14, 2005
  2. =?Utf-8?B?RGlmZmlkZW50?=

    Question on Page lifecycle...

    =?Utf-8?B?RGlmZmlkZW50?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    422
    Eliyahu Goldin
    Jan 11, 2006
  3. =?Utf-8?B?RGlmZmlkZW50?=

    Question on Page lifecycle...

    =?Utf-8?B?RGlmZmlkZW50?=, Feb 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    404
    Kevin Spencer
    Mar 1, 2006
  4. Hans Kesting

    Page lifecycle and dynamic controls

    Hans Kesting, Nov 3, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    467
    Mike Gleason jr Couturier
    Nov 3, 2008
  5. Sky
    Replies:
    7
    Views:
    641
Loading...

Share This Page