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 EditorPartCollection

 

Publicado: octubre de 2016

Contiene una colección de controles EditorPart utilizados para modificar las propiedades, el diseño, la apariencia y el comportamiento de los controles WebPart. 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.EditorPartCollection

public sealed class EditorPartCollection : ReadOnlyCollectionBase

NombreDescripción
System_CAPS_pubmethodEditorPartCollection()

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

System_CAPS_pubmethodEditorPartCollection(EditorPartCollection, ICollection)

Inicializa una nueva instancia de la EditorPartCollection clase pasando un EditorPartCollection colección de EditorPart controles y un ICollection colección de adicionales EditorPart controles.

System_CAPS_pubmethodEditorPartCollection(ICollection)

Inicializa una nueva instancia de la EditorPartCollection clase pasando un ICollection colección de EditorPart 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]

Devuelve a un miembro específico de la colección según un identificador único.

NombreDescripción
System_CAPS_pubmethodContains(EditorPart)

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

System_CAPS_pubmethodCopyTo(EditorPart[], Int32)

Copia la colección en una matriz de EditorPart controles.

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(EditorPart)

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.EditorPartCollection class is a read-only collection of T:System.Web.UI.WebControls.WebParts.EditorPart controls, typically used by an T:System.Web.UI.WebControls.WebParts.EditorZoneBase zone to track the set of T:System.Web.UI.WebControls.WebParts.EditorPart controls contained by the zone.

When a Web Parts page enters edit mode, and a user selects a control to edit, the editing process begins. The zone creates a new T:System.Web.UI.WebControls.WebParts.EditorPartCollection object consisting of the T:System.Web.UI.WebControls.WebParts.EditorPart controls contained by the zone. At various phases in the editing process, the zone accesses the T:System.Web.UI.WebControls.WebParts.EditorPartCollection object to save or retrieve property values between the T:System.Web.UI.WebControls.WebParts.EditorPart controls in the collection and the T:System.Web.UI.WebControls.WebParts.WebPart control currently being edited.

You can create an T:System.Web.UI.WebControls.WebParts.EditorPartCollection 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.EditorPart controls. Even though the T:System.Web.UI.WebControls.WebParts.EditorPartCollection object is read-only, you can make programmatic changes to the properties of the underlying controls referenced in the collection.

The following code example demonstrates several uses of the T:System.Web.UI.WebControls.WebParts.EditorPartCollection 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 edited by the T:System.Web.UI.WebControls.WebParts.EditorPart controls.

  • A Web page that references the TextDisplayWebPart control, contains an T:System.Web.UI.WebControls.WebParts.EditorZone control with several of the T:System.Web.UI.WebControls.WebParts.EditorPart controls from the Web Parts control set declared in the zone, and contains some event-driven code to create and manipulate an T:System.Web.UI.WebControls.WebParts.EditorPartCollection object.

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

The first part of this code example is the user control that enables users to change display modes on a Web page. For details about display modes and a description of the source code in this control, see Walkthrough: Changing Display Modes on a Web Parts Page.

<%@ control language="C#" classname="DisplayModeMenuCS"%>

<script runat="server">

 // Use a field to reference the current WebPartManager.
  WebPartManager _manager;

  void Page_Init(object sender, EventArgs e)
  {
    Page.InitComplete += new EventHandler(InitComplete);
  }  

  void InitComplete(object sender, System.EventArgs e)
  {
    _manager = WebPartManager.GetCurrentWebPartManager(Page);

    String browseModeName = WebPartManager.BrowseDisplayMode.Name;

    // Fill the dropdown with the names of supported display modes.
    foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
    {
      String modeName = mode.Name;
      // Make sure a mode is enabled before adding it.
      if (mode.IsEnabled(_manager))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }
    }
  }

  // Change the page to the selected display mode.
  void DisplayModeDropdown_SelectedIndexChanged(object sender, 
    EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;

    WebPartDisplayMode mode = 
      _manager.SupportedDisplayModes[selectedMode];
    if (mode != null)
      _manager.DisplayMode = mode;

  }

  void Page_PreRender(object sender, EventArgs e)
  {
    DisplayModeDropdown.SelectedValue = 
      _manager.DisplayMode.Name;
  }

</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="125" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
  <asp:Label ID="Label1" runat="server" 
    Text="&nbsp;Display Mode" 
    Font-Bold="true"
    Font-Size="8"
    Width="120" 
    AssociatedControlID="DisplayModeDropdown"/>
  <asp:DropDownList ID="DisplayModeDropdown" 
    runat="server"  
    AutoPostBack="true" 
    Width="120"
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
  </asp:Panel>
</div>

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. This custom property can be edited when the control is in edit mode, along with the standard T:System.Web.UI.WebControls.WebParts.WebPart control properties.

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:editorzone> element for the page contains declarations for three T:System.Web.UI.WebControls.WebParts.EditorPart controls. Two of these controls become part of a custom T:System.Web.UI.WebControls.WebParts.EditorPartCollection object that is created when the Button1_Click method executes.

<%@ page language="c#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenu" 
  Src="DisplayModecs.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(AppearanceEditorPart1);
    list.Add(PropertyGridEditorPart1);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
    {
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";
    }

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
    if(!myParts.Contains(LayoutEditorPart1))
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;

    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    myParts.CopyTo(partArray,1);
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
    {
      Label1.Text += ePart.Title + "<br />";
    }

  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>
      Text Display WebPart with AppearanceEditorPart
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <uc1:DisplayModeMenu ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server">
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" />          
        </zonetemplate>
      </asp:webpartzone> 
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server" />
          <asp:LayoutEditorPart ID="LayoutEditorPart1" 
            runat="server" />
          <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" 
            runat="server" />
        </ZoneTemplate>      
      </asp:EditorZone>
      <asp:Button ID="Button1" runat="server" 
        Text="Create EditorPartCollection" 
        OnClick="Button1_Click" />
      <asp:Label ID="Label1" runat="server" Text="" />
    </form>
  </body>
</html>

When you load the page in a browser, you can switch the page into edit mode by selecting Edit in the Display Mode drop-down list control. You can click the verbs menu (the downward arrow) in the title bar of the TextDisplayWebPart control, and click Edit to edit the control. When the editing user interface (UI) is visible, you can see all the T:System.Web.UI.WebControls.WebParts.EditorPart controls. You click the Create EditorPartCollection button to see the effects on the T:System.Web.UI.WebControls.WebParts.EditorPart controls that are created by the code that is manipulating the T:System.Web.UI.WebControls.WebParts.EditorPartCollection object. Also, notice that the T:System.Web.UI.WebControls.WebParts.PropertyGridEditorPart control allows you to edit the custom TextDisplayWebPart.ContentText property. This is possible because the property is marked with a WebBrowsable attribute in the source code for the control. If you update the property value in the editing UI, you must return the page to normal browse mode to see the effect of updating the TextDisplayWebPart.ContentText property.

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