WebPartManager.Zones Propiedad

Definición

Obtiene una referencia a una colección de todas las zonas WebPartZoneBase de una página Web.

public:
 property System::Web::UI::WebControls::WebParts::WebPartZoneCollection ^ Zones { System::Web::UI::WebControls::WebParts::WebPartZoneCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.WebControls.WebParts.WebPartZoneCollection Zones { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Zones : System.Web.UI.WebControls.WebParts.WebPartZoneCollection
Public ReadOnly Property Zones As WebPartZoneCollection

Valor de propiedad

WebPartZoneCollection

Colección WebPartZoneCollection que hace referencia a un conjunto de zonas WebPartZoneBase.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la Zones propiedad mediante programación para acceder a controles de zona individuales WebPartZoneBase . Observe que, en el marcado declarativo de la página web, hay dos <asp:webpartzone> elementos, cada uno que contiene un control de servidor. En la <script> sección de la página, el código usa la Zones propiedad para acceder a las zonas individuales, enumerar todos los identificadores de zona y, a continuación, cambiar el color de fondo en la segunda zona.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    foreach (WebPartZone zone in WebPartManager1.Zones)
    {
      Label1.Text += zone.ID + "<br />";
    }
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
    WebPartManager1.Zones["WebPartZone2"].BackColor = System.Drawing.Color.LightBlue;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <div>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links"
            ExportMode="All">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />        
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="List Zone IDs" 
        OnClick="Button1_Click" />
      <asp:Button ID="Button2" runat="server" 
        Text="Change Zone BackColor" 
        OnClick="Button2_Click" />  
      <br />
      <asp:Label ID="Label1" runat="server" text="" />
    </div>
    </form>
</body>
</html>
<%@ Page Language="vb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    Dim zone As WebPartZone
    For Each zone In WebPartManager1.Zones
      Label1.Text += zone.ID & "<br />"
    Next
  End Sub

  Protected Sub Button2_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    WebPartManager1.Zones("WebPartZone2").BackColor = _
      System.Drawing.Color.LightBlue
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <div>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links"
            ExportMode="All">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />        
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="List Zone IDs" 
        OnClick="Button1_Click" />
      <asp:Button ID="Button2" runat="server" 
        Text="Change Zone BackColor" 
        OnClick="Button2_Click" />  
      <br />
      <asp:Label ID="Label1" runat="server" text="" />
    </div>
    </form>
</body>
</html>

Tenga en cuenta que para que el ejemplo de código funcione, debe agregar una configuración en el archivo Web.config para habilitar la exportación de archivos de descripción elementos web. Asegúrese de que tiene un archivo Web.config en el mismo directorio que la página web para este ejemplo de código. En la <system.web> sección , asegúrese de que hay un <webParts> elemento con un enableExport atributo establecido trueen , como en el marcado siguiente.

<webParts enableExport="true">

...

</webParts>

Después de cargar la página en un explorador, si hace clic en el botón Id. de zona de lista, el código usa la Zones propiedad para enumerar los identificadores de todas las zonas de la colección. Si hace clic en el botón Cambiar zona BackColor , el código cambia el color de fondo de la segunda zona.

Comentarios

El Zones control utiliza la WebPartManager propiedad para realizar un seguimiento de las WebPartZoneBase zonas de una página web. Tenga en cuenta que la propiedad no hace referencia a todos los tipos de zonas; hace referencia solo a zonas que derivan de la WebPartZoneBase clase , incluidas WebPartZone las zonas.

Aunque la colección a la que hace referencia la propiedad es de solo lectura, puede usarla para acceder a los objetos individuales de la colección y trabajar con ellos mediante programación.

Se aplica a