WebPartManager.Zones Propriedade

Definição

Obtém uma referência a uma coleção de todas as zonas WebPartZoneBase em uma página da Web.Gets a reference to a collection of all the WebPartZoneBase zones on a Web page.

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

WebPartZoneCollection

Um WebPartZoneCollection que referencia um conjunto de zonas WebPartZoneBase.A WebPartZoneCollection that references a set of WebPartZoneBase zones.

Atributos

Exemplos

O exemplo de código a seguir demonstra como usar a Zones propriedade programaticamente para acessar WebPartZoneBase controles de zona individuais.The following code example demonstrates how to use the Zones property programmatically to access individual WebPartZoneBase zone controls. Observe que, na marcação declarativa para a página da Web, há dois <asp:webpartzone> elementos, cada um contendo um controle de servidor.Notice that in the declarative markup for the Web page, there are two <asp:webpartzone> elements, each containing a server control. Na <script> seção da página, o código usa a Zones propriedade para acessar as zonas individuais, listando todas as IDs de zona e, em seguida, alterando a cor do plano de fundo na segunda zona.In the <script> section of the page, the code uses the Zones property to access the individual zones, listing all the zone IDs and then changing the background color on the second zone.

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

Observe que, para que o exemplo de código funcione, você deve adicionar uma configuração no arquivo Web.config para habilitar a exportação Web Parts arquivos de descrição.Note that for the code example to work, you must add a setting in the Web.config file to enable exporting Web Parts description files. Verifique se você tem um arquivo de Web.config no mesmo diretório que a página da Web para este exemplo de código.Ensure that you have a Web.config file in the same directory as the Web page for this code example. Na <system.web> seção, verifique se há um <webParts> elemento com um enableExport atributo definido como true , como na marcação a seguir.Within the <system.web> section, make sure there is a <webParts> element with an enableExport attribute set to true, as in the following markup.

<webParts enableExport="true">

...

</webParts>

Depois de carregar a página em um navegador, se você clicar no botão listar IDs de zona , o código usará a Zones propriedade para listar as IDs de todas as zonas na coleção.After you load the page into a browser, if you click the List Zone IDs button, the code uses the Zones property to list the IDs of all zones in the collection. Se você clicar no botão alterar BackColor da zona , o código alterará a cor do plano de fundo da segunda zona.If you click the Change Zone BackColor button, the code changes the background color of the second zone.

Comentários

A Zones propriedade é usada pelo WebPartManager controle para acompanhar as WebPartZoneBase zonas em uma página da Web.The Zones property is used by the WebPartManager control to track the WebPartZoneBase zones on a Web page. Observe que a propriedade não faz referência a todos os tipos de zonas; Ele faz referência somente a zonas que derivam da WebPartZoneBase classe, incluindo WebPartZone zonas.Note that the property does not reference all types of zones; it references only zones that derive from the WebPartZoneBase class, including WebPartZone zones.

Embora a coleção referenciada pela propriedade seja somente leitura, você pode usá-la para acessar os objetos individuais na coleção e trabalhar com eles de forma programática.Although the collection referenced by the property is read-only, you can use it to access the individual objects in the collection and work with them programmatically.

Aplica-se a