Compartilhar via


PlaceHolder Web Server Control Declarative Syntax 

Reserves a location in the page control hierarchy for controls that are added programmatically.

<asp:PlaceHolder
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Visible="True|False"
/>

Remarks

Use the PlaceHolder control as a container to store dynamically added server controls to the Web page. The PlaceHolder control does not produce any visible output and is only used as a container for other controls on the Web page. You can use the Control.Controls collection to add, insert, or remove a control from the PlaceHolder control.

Example

The following example demonstrates how to add Web server controls to the PlaceHolder control.

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >

<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 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>

See Also

Reference

PlaceHolder

Other Resources

Web Server Control Syntax