我有一个面板,我正在尝试从后面的代码添加用户控件。问题是代码运行后加载的控件不会出现在面板中。我错过了什么吗?
<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);
}
答案 0 :(得分:0)
如果您正在处理真正的用户控件,显然您需要使用LoadControl。将我的代码更改为..
admin_InputControl control = (admin_InputControl)LoadControl("../controls/InputControl.ascx");
control.InitializeInputControl(ShippingDetailInputControls, new DataModels.EDIOrderShipmentInfo(), 1, "Shipment Details");
Panel1.Controls.Add(control);