is CreateChildControls automatically called within an object OnInit?

  • Thread starter Thread starter dx
  • Start date Start date
D

dx

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

TIA
 
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.
 
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
 
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
 
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
 
Back
Top