Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Clase CatalogPartCollection

 

Publicado: octubre de 2016

Contiene una colección de controles CatalogPart usados para proporcionar catálogos de controles de servidor web que los usuarios finales pueden agregar a una página web. Esta clase no puede heredarse.

Espacio de nombres:   System.Web.UI.WebControls.WebParts
Ensamblado:  System.Web (en System.Web.dll)

System.Object
  System.Collections.ReadOnlyCollectionBase
    System.Web.UI.WebControls.WebParts.CatalogPartCollection

public sealed class CatalogPartCollection : ReadOnlyCollectionBase

NombreDescripción
System_CAPS_pubmethodCatalogPartCollection()

Inicializa una nueva instancia vacía de la CatalogPartCollection clase.

System_CAPS_pubmethodCatalogPartCollection(CatalogPartCollection, ICollection)

Inicializa una nueva instancia de la CatalogPartCollection clase pasando un ICollection colección de existente CatalogPart controles en una zona y una colección adicional de controles.

System_CAPS_pubmethodCatalogPartCollection(ICollection)

Inicializa una nueva instancia de la CatalogPartCollection clase pasando un ICollection colección de CatalogPart controles.

NombreDescripción
System_CAPS_pubpropertyCount

Obtiene el número de elementos incluidos en la instancia de ReadOnlyCollectionBase.(Heredado de ReadOnlyCollectionBase).

System_CAPS_pubpropertyItem[Int32]

Obtiene o establece a un miembro de la colección, basándose en su posición en la colección.

System_CAPS_pubpropertyItem[String]

Devuelve a un miembro de la colección basándose en un identificador de cadena único.

NombreDescripción
System_CAPS_pubmethodContains(CatalogPart)

Devuelve un valor que indica si un control determinado existe en la colección.

System_CAPS_pubmethodCopyTo(CatalogPart[], Int32)

Copia la colección en una matriz de CatalogPart objetos.

System_CAPS_pubmethodEquals(Object)

Determina si el objeto especificado es igual al objeto actual.(Heredado de Object).

System_CAPS_pubmethodGetEnumerator()

Devuelve un enumerador que recorre en iteración el ReadOnlyCollectionBase instancia.(Heredado de ReadOnlyCollectionBase).

System_CAPS_pubmethodGetHashCode()

Sirve como la función hash predeterminada.(Heredado de Object).

System_CAPS_pubmethodGetType()

Obtiene el Type de la instancia actual.(Heredado de Object).

System_CAPS_pubmethodIndexOf(CatalogPart)

Devuelve la posición de un miembro específico de la colección.

System_CAPS_pubmethodToString()

Devuelve una cadena que representa al objeto actual. (Heredado de Object).

NombreDescripción
System_CAPS_pubfieldSystem_CAPS_staticEmpty

Hace referencia a una instancia estática, vacía de sólo lectura de la colección.

NombreDescripción
System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.CopyTo(Array, Int32)

Copia la totalidad de ReadOnlyCollectionBase en una matriz Array unidimensional compatible, comenzando en el índice especificado de la matriz de destino.(Heredado de ReadOnlyCollectionBase).

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.IsSynchronized

Obtiene un valor que indica si el acceso a un objeto ReadOnlyCollectionBase está sincronizado (es seguro para subprocesos).(Heredado de ReadOnlyCollectionBase).

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.SyncRoot

Obtiene un objeto que se puede utilizar para sincronizar el acceso a un objeto ReadOnlyCollectionBase.(Heredado de ReadOnlyCollectionBase).

NombreDescripción
System_CAPS_pubmethodAsParallel()

Sobrecargado. Habilita la paralelización de una consulta.(Definido por ParallelEnumerable).

System_CAPS_pubmethodAsQueryable()

Sobrecargado. Convierte un IEnumerable para un IQueryable.(Definido por Queryable).

System_CAPS_pubmethodCast<TResult>()

Convierte los elementos de un IEnumerable al tipo especificado.(Definido por Enumerable).

System_CAPS_pubmethodOfType<TResult>()

Filtra los elementos de un IEnumerable basado en un tipo especificado.(Definido por Enumerable).

The T:System.Web.UI.WebControls.WebParts.CatalogPartCollection class is a read-only collection of T:System.Web.UI.WebControls.WebParts.CatalogPart controls, typically used by a T:System.Web.UI.WebControls.WebParts.CatalogZoneBase zone to track the set of T:System.Web.UI.WebControls.WebParts.CatalogPart controls contained by the zone.

When a Web Parts page enters catalog mode, the zone creates a new T:System.Web.UI.WebControls.WebParts.CatalogPartCollection object consisting of the T:System.Web.UI.WebControls.WebParts.CatalogPart controls. Each T:System.Web.UI.WebControls.WebParts.CatalogPart control in the collection can contain references to zero or more Web server controls, which are displayed in the form of a catalog of available server controls.

You can create a T:System.Web.UI.WebControls.WebParts.CatalogPartCollection collection of controls for your own programmatic use if, for example, you need to perform some mass operation on a set of T:System.Web.UI.WebControls.WebParts.CatalogPart controls. Even though the T:System.Web.UI.WebControls.WebParts.CatalogPartCollection object is read-only, you can make programmatic changes to the underlying controls referenced in the collection.

The following code example demonstrates several uses of the T:System.Web.UI.WebControls.WebParts.CatalogPartCollection class. There are four parts to this code example:

  • A user control that enables you to change display modes on a Web Parts page.

  • A class for a custom T:System.Web.UI.WebControls.WebParts.WebPart control named TextDisplayWebPart, which is referenced in the Web page and is contained in one of the T:System.Web.UI.WebControls.WebParts.CatalogPart controls.

  • A Web page that references the TextDisplayWebPart control, contains a T:System.Web.UI.WebControls.WebParts.CatalogZone control with two of the T:System.Web.UI.WebControls.WebParts.CatalogPart controls from the Web Parts control set declared in the zone, and contains event-driven code to create and manipulate a T:System.Web.UI.WebControls.WebParts.CatalogPartCollection object.

  • An explanation of how the code example works when you load it in a browser.

The first part of the code example is the user control. The source code for the user control comes from another topic. For this code example to work, you need to obtain the .ascx file for the user control from the Walkthrough: Changing Display Modes on a Web Parts Page topic, and place the file in the same folder as the .aspx page in this code example.

The second part of the code example is the TextDisplayWebPart control. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Server Control. Note that the control has a property named ContentText; this property holds the value that the user enters in the text box.

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class TextDisplayWebPart : WebPart
  {
    private String _contentText = null;
    TextBox input;
    Label DisplayContent;
    Literal lineBreak;

    [Personalizable(), WebBrowsable]
    public String ContentText
    {
      get { return _contentText; }
      set { _contentText = value; }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      this.Controls.Add(DisplayContent);

      lineBreak = new Literal();
      lineBreak.Text = @"<br />";
      Controls.Add(lineBreak);

      input = new TextBox();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);

    }

    private void submit_Click(object sender, EventArgs e)
    {
      // Update the label string.
      if (input.Text != String.Empty)
      {
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }

  }
}

The third part of the code example is the Web page. Notice that the <asp:catalogzone> element for the page contains declarations for two T:System.Web.UI.WebControls.WebParts.CatalogPart controls. These controls become part of a custom T:System.Web.UI.WebControls.WebParts.CatalogPartCollection object that is created when the Button1_Click method executes. The T:System.Web.UI.WebControls.WebParts.PageCatalogPart control contains Web server controls that have been previously closed by a user at run time. Controls in the T:System.Web.UI.WebControls.WebParts.PageCatalogPart control can be added back to a page. The T:System.Web.UI.WebControls.WebParts.DeclarativeCatalogPart control contains a declaration of the custom TextDisplayWebPart control. When the page is in catalog mode, a user can add the TextDisplayWebPart control to the page so that it can be used in normal browse mode.

<%@ Page Language="C#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ Register TagPrefix="aspSample"
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="TextDisplayWebPartCS" %> 

<!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)
  {
    ArrayList list = new ArrayList(2);
    list.Add(PageCatalogPart1);
    list.Add(DeclarativeCatalogPart1);
    // Pass an ICollection object to the constructor.
    CatalogPartCollection myParts = new CatalogPartCollection(list);
    foreach (CatalogPart catalog in myParts)
    {
      catalog.Description = "My " + catalog.DisplayTitle;
    }

    // Use the IndexOf property to locate a CatalogPart control.
    int PageCatalogPartIndex = myParts.IndexOf(PageCatalogPart1);
    myParts[PageCatalogPartIndex].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if a CatalogPart control exists.
    if (myParts.Contains(PageCatalogPart1))
    {
      WebPart closedWebPart = null;
      WebPartDescriptionCollection descriptions = PageCatalogPart1.GetAvailableWebPartDescriptions();
      if (descriptions.Count > 0)
      {
        closedWebPart = PageCatalogPart1.GetWebPart(descriptions[0]);
        closedWebPart.AllowClose = false;
      }
    }

    // Use indexers to display the details of the CatalogPart controls.
    Label1.Text = String.Empty;
    Label1.Text =
      "<h3>PageCatalogPart Details</h3>" +
      "ID: " + myParts[0].ID + "<br />" +
      "Count: " + myParts[0].GetAvailableWebPartDescriptions().Count;
    Label1.Text += 
      "<h3>DeclarativeCatalogPart Details</h3>" +
      "ID: " + myParts["DeclarativeCatalogPart1"].ID + "<br />" +
      "Count: " + myParts["DeclarativeCatalogPart1"].GetAvailableWebPartDescriptions().Count;
  }
</script> 

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>PageCatalogPart Details</title>
</head>
<body>
  <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server" />
    <asp:WebPartZone ID="WebPartZone1" runat="server">
      <ZoneTemplate>
        <asp:BulletedList 
          ID="BulletedList1" 
          Runat="server"
          DisplayMode="HyperLink" 
          Title="Favorite Links" >
          <asp:ListItem Value="http://msdn.microsoft.com">
            MSDN
          </asp:ListItem>
          <asp:ListItem Value="http://www.asp.net">
            ASP.NET
          </asp:ListItem>
          <asp:ListItem Value="http://www.msn.com">
            MSN
          </asp:ListItem>
        </asp:BulletedList>
      </ZoneTemplate>
    </asp:WebPartZone>
    <asp:CatalogZone ID="CatalogZone1" runat="server">
      <ZoneTemplate>
        <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
          <WebPartsTemplate>
            <aspSample:TextDisplayWebPart runat="server" 
              id="TextDisplayWebPart1"
              Title="Text Display WebPart" />
          </WebPartsTemplate>
        </asp:DeclarativeCatalogPart>
        <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />  
      </ZoneTemplate>
    </asp:CatalogZone>
    <hr />
    <asp:Button ID="Button1" 
      runat="server" 
      Text="Display CatalogPart Properties" 
      OnClick="Button1_Click"/>
    <br />
    <asp:Label ID="Label1" runat="server" Text="" /> 
  </form>
</body>
</html>

When you load the page in a browser, you can switch the page into catalog mode by selecting Catalog in the Display Mode drop-down list control. You can add the custom T:System.Web.UI.WebControls.WebParts.WebPart control to the page by selecting the check box next to it and clicking Add. Click Close to return the page to browse mode. On the control you just added, if you click the verbs menu (the down arrow that appears in the title bar) and then click Close, the control is removed from the page and added to the T:System.Web.UI.WebControls.WebParts.PageCatalogPart control. Return the page to catalog mode, and click the Page Catalog link to view the contents of the T:System.Web.UI.WebControls.WebParts.PageCatalogPart control. Notice that the control you closed now appears there. Clicking the Display CatalogPart Properties button accesses the T:System.Web.UI.WebControls.WebParts.CatalogPartCollection object and displays certain properties of the contained T:System.Web.UI.WebControls.WebParts.CatalogPart controls.

.NET Framework
Disponible desde 2.0

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Volver al principio
Mostrar: