When Page.OnInit is done and exited, can I be sure that ALL child controls have called OnInit as wel

S

Sally

Just confused about when OnInit and Constructor gets called in the
parent/child case.


Page.Constructor()
Page.AddParsedSubObject() <- do all the sub's constructors get called
here?
Page.OnInit() Children.OnInit() (from what I have read, no particular
oder)

So where does CreateChildControls() come in and when
CreateChildControls() is done, does that mean that all
Children.OnInit() have been called?
 
B

bruce barker

in short no.

CreateChildControls is deferred for as long as possible. If your control
does not call EnsureChildControls (say no postback or viewstate handling
required), then it may not get called until PreRender (well after OnLoad).

AddParsedSubObject(), is used by the aspx parser to notify your control that
is parsed a control nested inside yours. your control is supposed to decide
what to do with this control. you may add it to your controls Controls
collection right away, or defer until CreateChildControls() is called if
needed.

OnInit is called close to control creation, but there is no control of the
timing. your controls children may be created first or after. as your
CreateChildControls() can create new controls on its own, this will not have
been Init'd yet.



-- bruce (sqlwork.com)
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top