主要功能:用作容器,从而将动态添加的服务器控件存储到网页中。可以使用 Control.Controls 集合在 PlaceHolder 控件中添加、插入或移除控件。
例如:动态生成label
<body>
<form runat= "server">
<body>
<form runat= "server">
<asp:PlaceHolder id=
"PlaceHolder1" runat=
"server"/>
<asp:Button ID="button1" Text="点我" runat="server"
OnClick="button1_onclick" ></asp:Button>
</form>
</body>
</form>
</body>
//.cs
public partial class _Default : System.Web.UI.Page
{
public partial class _Default : System.Web.UI.Page
{
void Page_Load(Object sender, EventArgs e)
{
}
{
}
protected void button1_onclick(object sender, EventArgs e)
{
Label label1 = new Label();
label1.Text = "show了吧^ ^";
PlaceHolder1.Controls.Add(label1); //添加
}
}
PlaceHolder1.Controls.Add(label1); //添加
}
}