[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Child controls being loaded BEFORE parent controls

Posted on 2007-08-07
Medium Priority
Last Modified: 2013-11-07
I'm tearing my hair out here!

I have a composite server control 'FilterList' which has a collection of child controls 'FilterField' which are themselves composite controls. they're declared like this:

<cc1:FilteredList ....>
        <cc1:FilterField ...
        <cc1:FilterField ...

Now, what's confusing me is that the CreateChildControls method of the FilterField controls is being called before the CreateChildControl of the FilteredList. And also, the this.Page is always null at this point. Why would that happen? It's meaning that none of my filterField controls are holding their data via the ViewState.

Please help before I'm completely bald.
Question by:senior_internet
  • 2
  • 2

Expert Comment

ID: 19648227
The OnInit method is the first method that is called in the page lifecycle.  LoadViewState is the third method so your viewstate data is not available when the child controls are initialized.  The control is stable in the Load event where it has been initialized and the state has been reconstructed.

Author Comment

ID: 19652257
Hi, thanks for the response,

Yeh I know about the page lifecycle but my problem is that the child controls are being created before their parent control. I want them to be created by the parent control in the CreateChildControls() method but they're not being. It seems the page is creating them so they end up with no parent (this.Parent is null) and no page (this.Page is null) and the viewstate doesn't work at all.

Accepted Solution

kev-dogg earned 2000 total points
ID: 19657898
Without some of your code it's difficult for me to see what is going on.  It could be as simple as forgetting to override the CreateChildControls method.

The child controls have to be added to their parent control before any child control properties are set and where this is done in the page lifecycle makes a huge difference.

This may help:  http://aspalliance.com/359

Author Comment

ID: 19660567
Thanks for your help. Having found the problem now, I can appreciate that you would have needed much more code to figure it out.

The problem was that the child controls had a property on them which called 'EnsureChildControls'. I was referencing this property too early in the page life cycle and therefore causing the CreateChildControls method to execute before it should have.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question