placeHolder在html页面中,并没有什么标记显示.它最大的作用就是能向其动态的添加控件.其中如果想向其添加Html标记,则要用LiteralControl来实现,
<body>
<form id="form1" runat="server">
<asp:PlaceHolder ID="PlaceHolder1" runat ="server" />
<asp:Button ID="button1" runat ="server" OnClick="button1_Click" Text ="ControlAdd" />
<asp:Label ID="lbMsg" runat ="server" />
</form>
</body>
protected void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < 3; i++)
{
Image img = new Image();
img.ImageUrl = @"images/"+i.ToString()+".bmp";
LiteralControl br = new LiteralControl("<br>");
PlaceHolder1.Controls.Add(img);
PlaceHolder1.Controls.Add(br);
}
lbMsg.Text = "添加成功!";
}
catch(Exception ex)
{
lbMsg.Text = ex.Message;
}
}