更新:2007 年 11 月
儲存 Web 網頁上以動態方式加入的伺服器控制項。
命名空間:
System.Web.UI.WebControls 組件:
System.Web (在 System.Web.dll 中)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class PlaceHolder _
Inherits Control
Dim instance As PlaceHolder
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class PlaceHolder : Control
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class PlaceHolder : public Control
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class PlaceHolder extends Control
public class PlaceHolder extends Control
使用 PlaceHolder 控制項做為容器,儲存 Web 網頁上以動態方式加入的伺服器控制項。PlaceHolder 控制項不會產生任何可見的輸出,只用來做為 Web 網頁上其他控制項的容器。您可以使用 Control..::.Controls 集合,在 PlaceHolder 控制項中加入、插入或移除控制項。
在下列程式碼範例中,會示範如何將控制項以動態方式加入 PlaceHolder 控制項。
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>PlaceHolder Example</title>
<script runat="server">
Sub Page_Load(Sender As Object, e As EventArgs)
Dim myButton As HtmlButton = New HtmlButton()
myButton.InnerText = "Button 1"
PlaceHolder1.Controls.Add(myButton)
myButton = New HtmlButton()
myButton.InnerText = "Button 2"
PlaceHolder1.Controls.Add(myButton)
myButton = New HtmlButton()
myButton.InnerText = "Button 3"
PlaceHolder1.Controls.Add(myButton)
myButton = New HtmlButton()
myButton.InnerText = "Button 4"
PlaceHolder1.Controls.Add(myButton)
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>PlaceHolder Example</h3>
<asp:PlaceHolder id="PlaceHolder1"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>PlaceHolder Example</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
HtmlButton myButton = new HtmlButton();
myButton.InnerText = "Button 1";
PlaceHolder1.Controls.Add(myButton);
myButton = new HtmlButton();
myButton.InnerText = "Button 2";
PlaceHolder1.Controls.Add(myButton);
myButton = new HtmlButton();
myButton.InnerText = "Button 3";
PlaceHolder1.Controls.Add(myButton);
myButton = new HtmlButton();
myButton.InnerText = "Button 4";
PlaceHolder1.Controls.Add(myButton);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>PlaceHolder Example</h3>
<asp:PlaceHolder id="PlaceHolder1"
runat="server"/>
</form>
</body>
</html>
System..::.Object
System.Web.UI..::.Control
System.Web.UI.WebControls..::.PlaceHolder
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
.NET Framework
支援版本:3.5、3.0、2.0、1.1、1.0
參考
其他資源