473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question for Gurus on CreateChildControls

I believe that when you instantiate a Control derived custom control that
implements the virtual method CreateChildControls(), that that base class
constructor in Control calls EnsureChildControls() which will invoke
CreateChildControls(). Am I correct?
Nov 17 '05 #1
6 2536
Could you explain a little further.
J

"Alex" <a.*******@verizon.net> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
I believe that when you instantiate a Control derived custom control that
implements the virtual method CreateChildControls(), that that base class
constructor in Control calls EnsureChildControls() which will invoke
CreateChildControls(). Am I correct?

Nov 17 '05 #2
"Alex" <a.*******@verizon.net> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
I believe that when you instantiate a Control derived custom control that
implements the virtual method CreateChildControls(), that that base class
constructor in Control calls EnsureChildControls() which will invoke
CreateChildControls(). Am I correct?


No. This is very incorrect. If this were the case, there would be no need
for a separate EnsureChildControls, since they would always be there.

A piece of code calls EnsureChildControls whenever it requires that the
child controls be present. If nothing else, ASP.NET will call
EnsureChildControls at the beginning of the PreRender phase.

A piece of code which is changing things in such a way as to cause a change
in the set of child controls should set "ChildControlsCreated = false" so
that the next time that EnsureChildControls is called, CreateChildControls
will be called.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #3
On [GMT+0100=CET],
John Saunders <jo***********@surfcontrol.com> thought hard and spewed:
"Alex" <a.*******@verizon.net> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
I believe that when you instantiate a Control derived custom control
that implements the virtual method CreateChildControls(), that that
base class constructor in Control calls EnsureChildControls() which
will invoke CreateChildControls(). Am I correct?


No. This is very incorrect. If this were the case, there would be no
need for a separate EnsureChildControls, since they would always be
there.

A piece of code calls EnsureChildControls whenever it requires that
the child controls be present. If nothing else, ASP.NET will call
EnsureChildControls at the beginning of the PreRender phase.

A piece of code which is changing things in such a way as to cause a
change in the set of child controls should set "ChildControlsCreated
= false" so that the next time that EnsureChildControls is called,
CreateChildControls will be called.


Please explain me then, why after I create a custom control using
Type.CreateInstance(), CreateChildControls() is invoked before my
constructor? Every time. Do you know for sure that Control constructor does
not invoke EnsureChildControls()?
Nov 17 '05 #4
"Alex" <a.*******@verizon.net> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
On [GMT+0100=CET],
John Saunders <jo***********@surfcontrol.com> thought hard and spewed:
"Alex" <a.*******@verizon.net> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
I believe that when you instantiate a Control derived custom control
that implements the virtual method CreateChildControls(), that that
base class constructor in Control calls EnsureChildControls() which
will invoke CreateChildControls(). Am I correct?
No. This is very incorrect. If this were the case, there would be no
need for a separate EnsureChildControls, since they would always be
there.

A piece of code calls EnsureChildControls whenever it requires that
the child controls be present. If nothing else, ASP.NET will call
EnsureChildControls at the beginning of the PreRender phase.

A piece of code which is changing things in such a way as to cause a
change in the set of child controls should set "ChildControlsCreated
= false" so that the next time that EnsureChildControls is called,
CreateChildControls will be called.


Please explain me then, why after I create a custom control using
Type.CreateInstance(), CreateChildControls() is invoked before my
constructor? Every time. Do you know for sure that Control constructor

does not invoke EnsureChildControls()?


Absolutely.

But why in the world are you creating controls using Type.CreateInstance???
That's sufficiently unusual that it might be the cause of your problem.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #5
On [GMT+0100=CET],
John Saunders <jo***********@surfcontrol.com> thought hard and spewed:
But why in the world are you creating controls using
Type.CreateInstance??? That's sufficiently unusual that it might be
the cause of your problem.


My architecture dictates a single-page(.aspx) with the content area being a
panel that can contain a different custom control depending on URL query
string. So I use query string parameters to form type name and use
Reflection API to create get the type and create instance. This is an
implementation of the Builder design pattern.
Nov 17 '05 #6
"Alex" <a.*******@verizon.net> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
On [GMT+0100=CET],
John Saunders <jo***********@surfcontrol.com> thought hard and spewed:
But why in the world are you creating controls using
Type.CreateInstance??? That's sufficiently unusual that it might be
the cause of your problem.
My architecture dictates a single-page(.aspx) with the content area being

a panel that can contain a different custom control depending on URL query
string. So I use query string parameters to form type name and use
Reflection API to create get the type and create instance. This is an
implementation of the Builder design pattern.


Interesting. In a similar situation, I've filled the panel with a calculated
user control. That allows "designer-type" people to create the content
visually. The same application also plays URL games so that users don't have
to see things like query strings.

I still don't know if the CreateInstance is your problem. As an experiment,
how about replacing your Type.CreateInstance with "new SomeControl()"? If
that works, but CreateInstance doesn't, it will tell you something.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
1
by: popman | last post by:
I develop a class which inherits textbox class.and I override the CreateChildControls method like code below: Protected Overrides Sub CreateChildControls() Controls.Add(New...
5
by: Dimitris Pantazopoulos | last post by:
Hello. Are there any known issues with the EnsureChildControls method? In a composite control, the Width property wraps the Width property of the TextBox child control: public Unit Width {...
0
by: Ferret | last post by:
I've found what seems to be a nasty bug in the DataGrid and Repeater classes. If CreateChildControls gets called before LoadViewState, ViewState fails to map and you end up with nothing on a...
5
by: Mark Olbert | last post by:
I have a composite control (under ASPNET2; derived from CompositeControl) which contains a label. The contents of the label are set when the control is created to a user-supplied value. What's...
3
by: Iain | last post by:
In my custom control I have overriden CreateChildControls and the first few lines look like this. protected override void CreateChildControls() { Debug.WriteLine("CreateChildControls",...
2
by: Michael | last post by:
Hi, I need to access view state data in my CreateChildControls method. Is there anyway to achieve that? I'm using ASP.NET 1.1. Thanks.
1
by: Michael | last post by:
Hi, I'm coding a custom server control, and CreateChildControls() is giving me some pain. I'm just wondering why we have CreateChildControls(), and why this methods seems to be called at...
1
by: xke | last post by:
I have a base class which overrides CreateChildControls / Render. Inside CreateChildControls, based on a public property ShowLinks in this class, I can include/display a usercontrol (kind of set of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.