0

I have a panel that I'm trying to add a user control to from the code behind. The issue is the loaded control does not appear in the panel once the code runs. Am I missing something?

    <div id="ShippingDetails" runat="server" visible="true">
        <asp:Panel ID="Panel1" runat="server"></asp:Panel>
    </div>
</form>
</asp:Content>

Code behind:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (OrderSearch1.SelectedValues != null)
    {
        InitializeShippingDetailControls();
    }
}

public void InitializeShippingDetailControls()
{
     admin_InputControl control = new admin_InputControl();
     control.InitializeInputControl(ShippingDetailInputControls, new DataModels.EDIOrderShipmentInfo(), 1, "Shipment Details");
     Panel1.Controls.Add(control);
}
mgmedick
  • 686
  • 7
  • 23

1 Answers1

0

Apparently you need to use LoadControl if you are dealing with a true user control. Changed my code to..

    admin_InputControl control = (admin_InputControl)LoadControl("../controls/InputControl.ascx");
    control.InitializeInputControl(ShippingDetailInputControls, new DataModels.EDIOrderShipmentInfo(), 1, "Shipment Details");
    Panel1.Controls.Add(control);
mgmedick
  • 686
  • 7
  • 23