According to Microsoft,The EnsureChildControls() method is called in order to make sure that child controls have been created.

I see many developers call EnsureChildControls() in CreateChildControls() or Render(). Also, I have figured out that most web parts or controls works fine even without explicitly calling EnsureChildControls().

Any thoughts on when and how calling EnsureChildControls() make sense?

2 Answers 2


The answer is obvious when you know that you don't need to call it if you don't want to. The child controls will be created for so you automatically.

The time when you want to call it yourself, is when you want to ensure that the child controls are there. For example, in a Render method, if you were going to consume a control, you would want to ensure that the control was there first otherwise a NullReferenceException would be thrown. So you would call EnsureChildControls() first just to make sure. In reality the controls almost certainly exist already by render but there may be other methods where you want to do a similar thing for initialization or data binding.


On CreateChildControls event all the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.

  • I already mentioned in the question what EnsureChildControls() does. The question is when exactly you would need ensure CreateChildControls called or not. Commented Nov 24, 2011 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.