我有一个 Web 表单,我在其中加载了一个 Web 用户控件(A)
当单击控件 A 上的按钮时,它会加载另一个名为的 Web 用户控件的数组infobox
当我将用户控件添加到 Web 用户控件 A 的控件集合中时,它不会显示。
下面是代码:点击控件A的按钮
foreach (Categories category in CategoriesDataList)
{
InfoBox ib = new InfoBox();
ib.LiteralName = category.Category_Name;
span_tempList.Controls.Add(ib);
ib = null;
}
span_tempList is a `<span>` tag with `runat=server`
下面是 InfoBox 控件的 HTML 和 cs 代码
public partial class InfoBox : System.Web.UI.UserControl
{
protected global::System.Web.UI.WebControls.Label ltrlName = new System.Web.UI.WebControls.Label();
protected void Page_Load(object sender, EventArgs e)
{
}
public InfoBox()
{
}
public string LiteralName
{
get { return ltrlName.Text; }
set { ltrlName.Text = value; }
}
}
--HTML--
<div style="width:10%;float:left;">
<asp:Label ID="ltrlName" runat="server" Text="Label"></asp:Label>
</div>
<div style="width:20%;float:left;">
<asp:Image ID="imgPicture" runat="server" ImageUrl="" />
</div>
<div style="width:70%;float:right;">
</div>
还尝试向页面添加控件不起作用