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?

link|improve this question

40% accept rate
feedback

1 Answer

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.

link|improve this answer
I already mentioned in the question what EnsureChildControls() does. The question is when exactly you would need ensure CreateChildControls called or not. – Amit Kumawat Nov 24 '11 at 15:14
feedback

Your Answer

 
or
required, but never shown

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