Export (0) Print
Expand All

EditorZone Class

Note: This class is new in the .NET Framework version 2.0.

Serves as the primary control in the Web Parts control set for hosting EditorPart controls on a Web page.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public class EditorZone : EditorZoneBase
public class EditorZone extends EditorZoneBase
public class EditorZone extends EditorZoneBase

Within the Web Parts control set, a zone is a composite control that covers a defined region on a Web page and contains server controls. The primary functions of a zone are to lay out the controls it contains, and to provide a common user interface (UI) for those controls. For general information about zones and how they are used in Web Parts applications, see the reference documentation for the base WebZone class, and Web Parts Control Set Overview.

The EditorZone control is one of the fundamental controls in the Web Parts control set. A key feature of Web Parts is the ability of end users to modify (or personalize) Web pages according to their preferences, and save their personalized settings for future browser sessions. One aspect of modifying Web Parts pages includes editing; users can edit the appearance, layout, behavior, and other properties of the visible WebPart controls. Several controls in the Web Parts control set provide the editing features, including the EditorZone control.

An EditorZone control becomes visible when a Web Parts page enters edit mode, and it makes available various EditorPart controls that can be used to personalize WebPart controls. The EditorZone control is very similar to its parent, the EditorZoneBase class, with one key difference: The EditorZone control provides a zone template, referenced in its ZoneTemplate property. The zone template adds the ability to declare content in the page persistence format. Page developers can place an EditorZone control in the declarative markup of a Web page, add a child <zonetemplate> element, and within the <zonetemplate> element, add declarative references to EditorPart controls.

The EditorZone control also has a method, CreateEditorParts, which overrides a base method in the EditorZoneBase class. This method is necessary so that an EditorZone control can create the zone template to contain any EditorPart controls that are added to the zone declaratively.

NoteNote

The buttons in the EditorZone UI require client-side scripting in order to work correctly. If scripting is disabled in the browser, the user will not be able to perform actions through the EditorZone UI.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

Notes to Inheritors If you want to create a custom EditorZone zone to gain greater control over the rendering of the editing UI, you can inherit directly from the EditorZoneBase class, as long as you do not need to provide zone template support for page developers to add EditorPart controls to your zone declaratively. In such a case, you would add all EditorPart controls to a zone programmatically. If you want to provide zone template support, you should inherit from the EditorZone class.

The following code example demonstrates several declarative and programmatic uses of the EditorZone class. The example creates a custom editor zone that inherits from the EditorZone class, and uses it in a Web Parts page.

The code example has three parts:

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

  • A Web page that references the custom EditorZone control.

  • An explanation of how the example works.

The first part of this code example is the user control that enables users to change display modes on a Web page. For more 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 + " Mode", 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:DropDownList ID="DisplayModeDropdown" 
    runat="server"  
    AutoPostBack="true" 
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
</div>

The second part of the code example is a Web page. Near the top of the page is a Register directive for the user control. The user control tag is declared in the page with a uc1: prefix for the element. Notice that below the <asp:WebPartZone> element is an <asp:EditorZone> element that contains several EditorPart controls, with some tags and properties set to determine its appearance and behavior. There are also a number of methods that access various members of the EditorZone control programmatically.

<%@ Page Language="C#" %>
<%@ register tagprefix="uc1" 
  tagname="DisplayModeMenuCS" 
  src="displaymodecs.ascx" %>
  
<script runat="server">

  void Button1_Click(object sender, EventArgs e)
  {
    if (EditorZone1.ApplyVerb.Enabled == true)
      EditorZone1.ApplyVerb.Enabled = false;
    else
      EditorZone1.ApplyVerb.Enabled = true;
  }

  void Button2_Click(object sender, EventArgs e)
  {
    EditorZone1.BorderWidth = 2;
    EditorZone1.BorderColor = System.Drawing.Color.DarkBlue;
  }

  void Button3_Click(object sender, EventArgs e)
  {
    Label1.Text = "<br />";
    foreach (EditorPart part in EditorZone1.EditorParts)
    {
      Label1.Text += part.ID + "<br />";
    }
  }

  void Button4_Click(object sender, EventArgs e)
  {
    EditorZone1.InstructionText = "My custom instruction text.";
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>EditorZoneBase Examples</title>
</head>
<body>
  <form id="form1" runat="server">
    <asp:WebPartManager ID="mgr" runat="server" />
    <uc1:DisplayModeMenuCS runat="server" id="displaymodemenu1" />
    <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>
        <asp:Calendar ID="Calendar1" Runat="server" 
          Title="My Calendar" />
      </ZoneTemplate>
    </asp:WebPartZone>
    <asp:EditorZone ID="EditorZone1" runat="server" >
      <VerbStyle Font-Italic="true" />
      <EditUIStyle BackColor="lightgray" />
      <PartChromeStyle BorderWidth="1" />
      <LabelStyle Font-Bold="true" />
      <CancelVerb Text="Cancel Changes" />
      <ZoneTemplate>
        <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
          runat="server" />
        <asp:LayoutEditorPart ID="LayoutEditorPart1" 
          runat="server" />
      </ZoneTemplate>
    </asp:EditorZone>
    <hr />
    <asp:Button ID="Button1" runat="server" Width="200"
      Text="Enable or Disable Apply" OnClick="Button1_Click" />
    <br />
    <asp:Button ID="Button2" runat="server" Width="200"
      Text="Set Zone BorderColor" OnClick="Button2_Click" />
    <br />
    <asp:Button ID="Button3" runat="server" Width="200"
      Text="Display EditorPart Collection" OnClick="Button3_Click" />
    <asp:Label ID="Label1" runat="server" />
    <br />
    <asp:Button ID="Button4" runat="server" Width="200"
      Text="Set Instruction Text" OnClick="Button4_Click" /> 
  </form>
</body>
</html>

When you load the page in a browser, you can select Edit Mode in the drop-down list to switch to edit mode. To display the editing UI, you can click the verbs menu (the downward arrow) in the title bar of one of the two controls, and click Edit to edit the control. With the editing UI visible, you can see the effects of the declarative and programmatic uses of the EditorZone class members.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft