Life cycle order for parent child relations

F

foldface

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
 
F

foldface

start here:

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?
 
A

Anders Borum

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.
 
F

foldface

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
 
F

foldface

Anders Borum said:
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. "
 
A

Anders Borum

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!
 
A

Anders Borum

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top