views:

349

answers:

1

When programmatically adding user controls using LoadControl(string path), when, in the user control's page life cycle, does it initialize its sub-controls with its viewstate?

I'm asking this question because one of my user controls that's being programmatically loaded has a TextBox control that is not being initialized/loaded by it's viewstate on PostBack on the Page_Load event (which is not the case for a regular .aspx pages and hence my confusion). Overall, I need to retrieve values from the Textbox control.

Thanks

+6  A: 
Joel Coehoorn
Thanks! On a related note, the user control that I'm adding programmatically happens in another user control that is being loaded declaratively. This declared parent user-control's PreInit event doesn't get fired (so the method 'protected void Page_PreInit(object sender, EventArgs e)' doesn't get called).Do you know why Page_PreInit doesn't get called in this declared user-control?
burnt1ce
Controls themselves don't have a pre-init, because the control page lifecycle events are called from the page and at the PreInit point the controls aren't all ready yet. Use Init instead.
Joel Coehoorn
Thank you very much. Your suggestion saved me. =)
burnt1ce