Life cycle order for parent child relations

Discussion in 'ASP .Net Web Controls' started by foldface@yahoo.co.uk, Nov 16, 2003.

  1. Guest

    Hi
    I'm trying to find the EXACT order of lifecycle calls for web pages
    and
    webcontrols.
    I created a control that inherits from Button but has LifeCycle
    print statements in it, e.g.

    protected override void TrackViewState()
    {
    base.TrackViewState();
    Page.Trace.Write(this.ID, "In TrackViewState...");
    }

    I created a web page that has this control on it, plus a UserControl
    that holds nothing but this control.

    I also put trace statments on the web page. The results are shown
    below,
    Note that:
    Level2 - Contol on the UserControl
    Level1 - Control on the web page
    <blank> the web page


    aspx.page Begin Init
    Level1 In Init... 0.004872 0.004872
    Level1 In TrackViewState... 0.006841 0.001968
    Level2 In Init... 0.006949 0.000108
    Level2 In TrackViewState... 0.006987 0.000038
    In Init... 0.011638 0.004651
    In TrackViewState... 0.012232 0.000594
    aspx.page End Init 0.012295 0.000063
    In Load... 0.014985 0.002690
    Level1 In Load... 0.015653 0.000668
    Level2 In Load... 0.015974 0.000321
    aspx.page Begin PreRender 0.016031 0.000058
    In PreRender... 0.018502 0.002471
    Level1 In PreRender... 0.019241 0.000739
    Level2 In PreRender... 0.019311 0.000071
    aspx.page End PreRender 0.019351 0.000039
    In SaveViewState... 0.021690 0.002339
    Level1 In SaveViewState... 0.041467 0.019777
    Level2 In SaveViewState... 0.043344 0.001877
    aspx.page Begin SaveViewState 0.043958 0.000614
    In SaveViewState... 0.065334 0.021376
    Level1 In SaveViewState... 0.065457 0.000123
    Level2 In SaveViewState... 0.065503 0.000046
    aspx.page End SaveViewState 0.065707 0.000204
    aspx.page Begin Render 0.065758 0.000052
    Level1 In Render... 0.444391 0.378633
    Level2 In Render... 0.444745 0.000353
    In Render... 0.447510 0.002765
    aspx.page End Render 0.447620 0.000111


    Results:
    - Note that for InInit and Render the parent is called last, which
    is what I would expect, for Load, PreRender and SaveViewState the
    parent is called first.

    I want to know the exact order of initialisation with regard to
    controls
    on web pages and parent/child relations. Where can I find this info,
    I was personally expecting the parent to be called last for all
    methods
    and was quite surprised by this.

    Thanks for any replies

    F
     
    , Nov 16, 2003
    #1
    1. Advertising

  2. Alvin Guest

    start here:
    http://www.15seconds.com/Issue/020102.htm
    this may also help you
    http://www.eggheadcafe.com/articles/20030211.asp
    understand the full process

    regards

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    <> wrote in message
    news:...
    > Hi
    > I'm trying to find the EXACT order of lifecycle calls for web pages
    > and
    > webcontrols.
    > I created a control that inherits from Button but has LifeCycle
    > print statements in it, e.g.
    >
    > protected override void TrackViewState()
    > {
    > base.TrackViewState();
    > Page.Trace.Write(this.ID, "In TrackViewState...");
    > }
    >
    > I created a web page that has this control on it, plus a UserControl
    > that holds nothing but this control.
    >
    > I also put trace statments on the web page. The results are shown
    > below,
    > Note that:
    > Level2 - Contol on the UserControl
    > Level1 - Control on the web page
    > <blank> the web page
    >
    >
    > aspx.page Begin Init
    > Level1 In Init... 0.004872 0.004872
    > Level1 In TrackViewState... 0.006841 0.001968
    > Level2 In Init... 0.006949 0.000108
    > Level2 In TrackViewState... 0.006987 0.000038
    > In Init... 0.011638 0.004651
    > In TrackViewState... 0.012232 0.000594
    > aspx.page End Init 0.012295 0.000063
    > In Load... 0.014985 0.002690
    > Level1 In Load... 0.015653 0.000668
    > Level2 In Load... 0.015974 0.000321
    > aspx.page Begin PreRender 0.016031 0.000058
    > In PreRender... 0.018502 0.002471
    > Level1 In PreRender... 0.019241 0.000739
    > Level2 In PreRender... 0.019311 0.000071
    > aspx.page End PreRender 0.019351 0.000039
    > In SaveViewState... 0.021690 0.002339
    > Level1 In SaveViewState... 0.041467 0.019777
    > Level2 In SaveViewState... 0.043344 0.001877
    > aspx.page Begin SaveViewState 0.043958 0.000614
    > In SaveViewState... 0.065334 0.021376
    > Level1 In SaveViewState... 0.065457 0.000123
    > Level2 In SaveViewState... 0.065503 0.000046
    > aspx.page End SaveViewState 0.065707 0.000204
    > aspx.page Begin Render 0.065758 0.000052
    > Level1 In Render... 0.444391 0.378633
    > Level2 In Render... 0.444745 0.000353
    > In Render... 0.447510 0.002765
    > aspx.page End Render 0.447620 0.000111
    >
    >
    > Results:
    > - Note that for InInit and Render the parent is called last, which
    > is what I would expect, for Load, PreRender and SaveViewState the
    > parent is called first.
    >
    > I want to know the exact order of initialisation with regard to
    > controls
    > on web pages and parent/child relations. Where can I find this info,
    > I was personally expecting the parent to be called last for all
    > methods
    > and was quite surprised by this.
    >
    > Thanks for any replies
    >
    > F
     
    Alvin, Nov 16, 2003
    #2
    1. Advertising

  3. Guest

    > start here:
    > http://www.15seconds.com/Issue/020102.htm
    > this may also help you
    > http://www.eggheadcafe.com/articles/20030211.asp
    > understand the full process


    Thanks for the links but unless I'm being thick (a distinct possiblilty)
    they don't answer the specific question. Its the parent/child relationships
    I'm curious about. For any random lifecycle call, OnInit, OnLoad, will they
    be called:
    - Parent.OnLoad() -> Child1.OnLoad() -> Child2.OnLoad()
    - Child1.OnLoad() -> Child2.OnLoad() -> Parent.OnLoad()
    - not fixed?


    > I want to know the exact order of initialisation with regard to
    > controls
    > on web pages and parent/child relations. Where can I find this info,
    > I was personally expecting the parent to be called last for all
    > methods
    > and was quite surprised by this.
     
    , Nov 17, 2003
    #3
  4. Anders Borum Guest

    Interesting thread. I'm looking forward to see, what you'll come up with!
    Keep up the good work. I've had little luch finding more advanced
    information on the lifecycle of controls.

    --
    venlig hilsen / with regards
    anders borum
    --
     
    Anders Borum, Nov 17, 2003
    #4
  5. Guest

    A little elaboration, are the web form lifecycle methods called first
    or last

    - Init, last
    - TrackViewState (always called immeadiately after above so treat as one call)
    - Load, first
    - PreRender, first
    - SaveViewstate, first
    - Render, the parent class is calling render on the child classes during
    the call.

    If I knew that this would ALWAYS be the case or it would vary I'd be happy
     
    , Nov 17, 2003
    #5
  6. Guest

    "Anders Borum" <> wrote in message news:<u#>...
    > Interesting thread. I'm looking forward to see, what you'll come up with!
    > Keep up the good work. I've had little luch finding more advanced
    > information on the lifecycle of controls.


    this is pretty good:
    http://authors.aspalliance.com/PaulWilson/Articles/?id=6

    Also I asked the author about execution order, this was the reply:

    "All methods that I know of, except OnInit, start with the parent and proceed
    to the children. OnInit is different, and this makes since if you think about
    it -- how can a parent control be initialized completely if its children still
    are not initialized. "
     
    , Nov 20, 2003
    #6
  7. Anders Borum Guest

    Re: Fragment caching fails when loading dynamically. Naming conflicts!

    Hello!

    By the way - the controls are loaded and added to the Page hierarchy in the
    Page.Init event. Not sure if this is any help, but I've tried starting the
    recursing in the Page.Load too, with no luck!

    --
    venlig hilsen / with regards
    anders borum
    --
     
    Anders Borum, Nov 22, 2003
    #7
  8. Anders Borum Guest

    Re: Fragment caching fails when loading dynamically. Naming conflicts!

    Actually, a little test I wrote this night (couldn't sleep - the problem
    crossed my mind) indicates that the "error" is caused by different behaviour
    from using the LoadControl() method on the Page or UserControl class.

    I'm getting correct results when using the LoadControl() method, inherited
    from a UserControl, but using the one on the Page class fails. I bet this is
    related to INamingContainer in some way. Perhaps the loaded UserControl is
    treatet differently (naming-wise) in the two implementations.

    I'll look into the system.web.dll later (decompile it) and see what's going
    on. Strange!

    --
    venlig hilsen / with regards
    anders borum
    --
     
    Anders Borum, Nov 22, 2003
    #8
    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. Suzanne Vogel
    Replies:
    16
    Views:
    595
    Jeff Schwab
    Dec 30, 2003
  2. Sally

    What is the life cycle when there are child controls?

    Sally, Apr 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    5
    Views:
    335
    Victor Garcia Aprea [MVP]
    Apr 25, 2004
  3. Replies:
    0
    Views:
    227
  4. Noel Dolan
    Replies:
    0
    Views:
    274
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    182
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page