views:

31

answers:

0

Hello all,

While nerding my way through the day again. I came across a problem concerning adding children to an already add child control.

I can add the controls, but when trying to use the controls in the added control, they all return null.

This is the method:

protected override CreateChildControls(EventArgs e)
{
    UserControl uControl = LoadControl("~/controls/TwoColumn.ascx");
    PlaceHolder holder = uControl.Controls.FindControl(phrContentMiddle) as PlaceHolder;
    holder.Controls.Add(LoadControl("~/controls/ImageShowControl");
}

When i try to call any type of button/UserControl inside the ImageShowControl.... All return null. Is this something in the Page LifeCycle?

If so, what is the way to go to realize this?

EDIT: I'm working my way through The Page life cycle... And am seeing that all nested controls in a page have an outer to inner event firing system. Except for Init and Unload()... Does this mean that I cannot use conventional methods like accessing or setting Button values in het Page_Load of the user control? Do i have to use The OnInit in user controls??

EDIT: I just found out that when I load the control using

 ImageShowControl imageShowControl = ImageShowControl)base.Page.LoadControl(System.IO.Path.Combine("controls", "ImageShowControl.ascx"));

it works.... but using the same loadControl method WITH parameters for the constructor, it does not load the WebControls, but it does have the parameters in the instance of ImageShowControl.

Why is this occuring?