is CreateChildControls automatically called within an object OnInit?

D

dx

If not is it appropriate to place an EnsureChildControls within an objects
OnInit method?

TIA
 
K

Kevin Spencer

Not unless the object is a Composite ASP.Net Server Control.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
T

Teemu Keiski

On initial request (non-postback) EnsureChildControls is called at PreRender
stage of the Page. At postback it is called when postback data handling for
the first control occurs, that is when FindControl is called which
automatically invokes EnsureChildControls first. This happens before
Page_Load at first postback data processing stage.

Why would you need this?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

If not is it appropriate to place an EnsureChildControls within an objects
OnInit method?

TIA
 
D

dx

Thanks Kevin, I appreciate your response. I'm trying to follow you full
circle.. can u help me understand these related questions.

Does .NET identify the object as a composite asp.net server control because
CreateChildControls is overriden? or because the objects inherits from
webcontrol? If not, how does .NET know this object is a composite control?

And what kicks off the OnInit call for the composite control?

Thanks again,
stan
 
T

Teemu Keiski

Um...the pattern to build a composite control is that it overrides
CreateChildControls as well as implements INamingContainer marker interface
to outcome naming conflicts as well as guide in postback processing. There's
not such step as 'recognize' composite control, but rather there are these
steps that composite controls usually follow.

Article about composite controls:
http://aspalliance.com/359

OnInit method is part of general control lifecycle which is called when
control reaches initialization stage, true task of OnInit method is to raise
Init event. See resources about control lifecycle in this blog posts:
http://weblogs.asp.net/eporter/archive/2003/07/15/10109.aspx

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


Thanks Kevin, I appreciate your response. I'm trying to follow you full
circle.. can u help me understand these related questions.

Does .NET identify the object as a composite asp.net server control because
CreateChildControls is overriden? or because the objects inherits from
webcontrol? If not, how does .NET know this object is a composite control?

And what kicks off the OnInit call for the composite control?

Thanks again,
stan
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top