Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Life cycle order for parent child relations

Reply
Thread Tools

Life cycle order for parent child relations

 
 
foldface@yahoo.co.uk
Guest
Posts: n/a
 
      11-16-2003
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
 
Reply With Quote
 
 
 
 
Alvin
Guest
Posts: n/a
 
      11-16-2003
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
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
 
foldface@yahoo.co.uk
Guest
Posts: n/a
 
      11-17-2003
> 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.

 
Reply With Quote
 
Anders Borum
Guest
Posts: n/a
 
      11-17-2003
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
--


 
Reply With Quote
 
foldface@yahoo.co.uk
Guest
Posts: n/a
 
      11-17-2003
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
 
Reply With Quote
 
foldface@yahoo.co.uk
Guest
Posts: n/a
 
      11-20-2003
"Anders Borum" <(E-Mail Removed)> wrote in message news:<u#(E-Mail Removed)>...
> 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/PaulW...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. "
 
Reply With Quote
 
Anders Borum
Guest
Posts: n/a
 
      11-22-2003
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
--


 
Reply With Quote
 
Anders Borum
Guest
Posts: n/a
 
      11-22-2003
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
--


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Parent/Child relations - Trying to access child control for save tnt_lu@hotmail.com ASP .Net Datagrid Control 0 04-15-2005 12:50 PM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM
What is the life cycle when there are child controls? Sally ASP .Net Building Controls 5 04-25-2004 10:53 PM
testing parent-child relations using only id's Suzanne Vogel C++ 16 12-30-2003 03:34 AM



Advertisments