0

我有一个面板,我试图从后面的代码中添加一个用户控件。问题是一旦代码运行,加载的控件就不会出现在面板中。我错过了什么吗?

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

后面的代码:

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);
}
4

1 回答 1

0

显然,如果您正在处理真正的用户控件,则需要使用 LoadControl。将我的代码更改为..

    admin_InputControl control = (admin_InputControl)LoadControl("../controls/InputControl.ascx");
    control.InitializeInputControl(ShippingDetailInputControls, new DataModels.EDIOrderShipmentInfo(), 1, "Shipment Details");
    Panel1.Controls.Add(control);
于 2013-09-30T20:13:11.750 回答