我正在从文件后面的代码创建一个表格并放置一个占位符。
//在Main.aspx上
MyControl control1 = (MyControl)Page.LoadControl("MyControl.ascx");
control1.ID = "ctl1";
MyControl control2 = (MyControl)Page.LoadControl("MyControl.ascx");
control2.ID = "ctl2";
MyControl control3 = (MyControl)Page.LoadControl("MyControl.ascx");
control3.ID = "ctl3";
MyControl control4 = (MyControl)Page.LoadControl("MyControl.ascx");
control4.ID = "ctl4";
Table table = new Table();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();
TableCell cell4 = new TableCell();
TableRow row1 = new TableRow();
table.Style.Add(HtmlTextWriterStyle.Position, "absolute");
cell1.Controls.Add(control1);
row1.Cells.Add(cell1);
cell1.Style.Add(HtmlTextWriterStyle.Position, "absolute");
cell2.Controls.Add(control2);
row1.Cells.Add(cell2);
cell2.Style.Add(HtmlTextWriterStyle.Position, "absolute");
cell3.Controls.Add(control3);
row1.Cells.Add(cell3);
cell3.Style.Add(HtmlTextWriterStyle.Position, "absolute");
cell4.Controls.Add(control4);
row1.Cells.Add(cell4);
cell4.Style.Add(HtmlTextWriterStyle.Position, "absolute");
table.Rows.Add(row1);
placeHolder1.Controls.Add(table);
//在 MyControl.ascx 上(我在这里放置控件;它是用 javascript 创建的)
<table cellpadding="0" cellspacing="0" border="0" width="217px"
style="position:relative" >
<tr>
<td >
<div id="c1" class="gauge" style="margin:0;padding:0;height:169px;width:217px;">
</div>
</td>
</tr>
// 在用户控件的 CSS 中
div.gauge
{
background-repeat: no-repeat;
background-position: top center;
height: 169px;
margin: 0px;
overflow: visible;
position: absolute;
width: 217px;
z-index: 0;
}
但我看到只有第一个控件被加载,其他的没有。有什么遗漏吗?