PlaceHolder Class
.NET Framework 3.0
Stores dynamically added server controls on the Web page.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
Use the PlaceHolder control as a container to store server controls that are dynamically added to the Web page. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page. You can use the Control.Controls collection to add, insert, or remove a control in the PlaceHolder control.
Topic | Location |
---|---|
How to: Create Templated ASP.NET User Controls | Building ASP .NET Web Applications |
How to: Add Controls to an ASP.NET Web Page Programmatically | Building ASP .NET Web Applications |
How to: Add PlaceHolder Web Server Controls to a Web Forms Page | Building ASP .NET Web Applications |
How to: Create Instances of ASP.NET User Controls Programmatically | Building ASP .NET Web Applications |
How to: Create Templated ASP.NET User Controls | Building ASP .NET Web Applications |
How to: Add Controls to an ASP.NET Web Page Programmatically | Building ASP .NET Web Applications |
How to: Add PlaceHolder Web Server Controls to a Web Forms Page | Building ASP .NET Web Applications |
How to: Create Instances of ASP.NET User Controls Programmatically | Building ASP .NET Web Applications |
How to: Add PlaceHolder Web Server Controls to a Web Forms Page (Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
The following code example demonstrates how to dynamically add controls to the PlaceHolder control.
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" > <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>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Show: