Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

EditorZoneBase Class

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

Serves as the base class for all zone controls that act as containers for EditorPart controls.

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

public abstract class EditorZoneBase : ToolZone
public abstract class EditorZoneBase extends ToolZone
public abstract class EditorZoneBase extends ToolZone

The EditorZoneBase class is a specialized zone class that inherits from the ToolZone class and provides a base set of behaviors for derived zones that contain EditorPart controls. There are several other types of ToolZone classes; for more information, see the overview topic for the ToolZone class. Like other tool zones, EditorZoneBase zones are not visible when a page is in normal browse mode; they are visible only when a page is in edit display mode. Also like the other tool zones, EditorZoneBase zones can only contain the special type of controls they were designed to contain (in this case, EditorPart controls).

The EditorZoneBase zones provide a special UI for the editing controls they contain. Many of these UI elements are common to all zones in the Web Parts control set. For a detailed discussion of the common UI elements in Web Parts zones, see the class overview topic for the WebZone class.

Because the EditorZoneBase class is abstract, you cannot use it directly on a Web page. Instead, you must use a control that inherits from the EditorZoneBase class and implements its behavior. You can either use the derived zone that is provided in the Web Parts control set, the EditorZone control, or you can derive your own custom EditorZoneBase control.

The EditorZoneBase class provides a common user interface (UI) to contain special controls that enable end users to edit the properties, layout, appearance, and other attributes of WebPart controls. Some properties that apply to the UI refer to verbs, such as the ApplyVerb, CancelVerb, and OKVerb properties. Verbs are common actions carried out by users on a page, and are represented in the UI by buttons, links, menu items, or other elements. For example, when users edit properties on a control they can click an apply verb to save the changes.

Several other properties affect text that is displayed at various points in the editing UI. These include the EmptyZoneText, ErrorText, HeaderText, and InstructionText properties.

Two important properties provide references to related controls. The EditorParts property is a collection of the EditorPart controls contained in the zone. The WebPartToEdit property is an object reference to a control contained in a WebPartZone--which might be a WebPart control or any other ASP.NET server control, user control, or custom control currently being edited.

Finally, the EditorPartChrome property references an instance of an EditorPartChrome object that is associated with the zone, and that contains style characteristics of the peripheral UI elements (known as chrome) such as title and border styles for EditorPart controls in the zone.

A number of the methods of the EditorZoneBase class are specialized to handle the editing of other controls. The Close method changes the page from the edit display mode back to a normal browsing view. The CreateEditorPartChrome method is for creating the chrome (peripheral UI elements such as a border, verbs, icons, and a title) that surrounds each EditorPart control in the zone. The CreateEditorParts method is an abstract method; derived classes override it to create instances of all the EditorPart controls contained in the zone. The InvalidateEditorParts method can be called by a derived class if the collection of EditorPart controls in the zone changes for some programmatic reason, which flags the Web Parts control set to recreate and update the collection of EditorPart controls. The OnDisplayModeChanged method is used to set the collection of EditorPart controls to a null reference (Nothing in Visual Basic) when the display mode changes from edit mode back to browse mode. Finally, the OnSelectedWebPartChanged method is used for handling the event when a WebPart control is either entering or leaving edit mode. For example, this method is a convenient place to synchronize the property values of a WebPart control with the editable values in the associated EditorPart controls.

Notes to Inheritors If you want to develop a custom zone for hosting EditorPart controls, you must determine whether you want to provide zone template support. A zone template is created by types that implement the ITemplate interface, and is necessary if you want to enable page developers using your custom zone to reference EditorPart controls within your zone in the declarative markup of a Web page. If you need zone template support, you should inherit from the EditorZone class. In contrast, if your custom zone and its EditorPart controls are going to be self-contained, and they will be created programmatically without any options for page developers to specify controls declaratively in a zone template, then you can inherit directly from the EditorZoneBase class. If you do this, it is critical that you implement the CreateEditorParts method so that your custom zone will work.

The following code example demonstrates several declarative and programmatic uses of the EditorZoneBase class. Because the class is abstract, the code examples use the derived EditorZone class that ships with the Web Parts control set, demonstrating the properties and methods that it inherits from the EditorZoneBase class.

The code example has four parts:

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

  • A Web page that contains an EditorZone control.

  • A custom EditorZone class that demonstrates some of the EditorZoneBase class members.

  • A description of how the example works in a browser.

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 a Web page that contains a declarative reference to an EditorZone control. 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:DisplayModeMenu> element. Notice that below the <asp:WebPartZone> element is an <asp:EditorZone> element that contains EditorPart controls, and has a variety of tags and properties set to determine its appearance and behavior. Most of the code in the page demonstrates the various programmatic uses of the EditorZoneBase properties and methods.

<%@ Page Language="C#" %>
<%@ register tagprefix="uc1" 
  tagname="DisplayModeMenuCS" 
  src="displaymodecs.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" %>
  
<script runat="server">

  void Button1_Click(object sender, EventArgs e)
  {
    if (EditorZone1.ApplyVerb.Enabled)
      EditorZone1.ApplyVerb.Enabled = false;
    else
      EditorZone1.ApplyVerb.Enabled = true;
  }
  void Button2_Click(object sender, EventArgs e)
  {
    if (EditorZone1.CancelVerb.Enabled)
      EditorZone1.CancelVerb.Enabled = false;
    else
      EditorZone1.CancelVerb.Enabled = true;
  }
  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)
  {
    if (EditorZone1.OKVerb.Enabled)
      EditorZone1.OKVerb.Enabled = false;
    else
      EditorZone1.OKVerb.Enabled = true;
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>EditorZoneBase Examples</title>
</head>
<body>
  <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" 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>
    <aspSample:MyEditorZone ID="EditorZone1" runat="server">
      <ApplyVerb Text="Apply Changes" />
      <CancelVerb Text="Cancel Changes" />
      <OKVerb Text="Finished" />
      <ZoneTemplate>
        <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
          runat="server" />
        <asp:LayoutEditorPart ID="LayoutEditorPart1" 
          runat="server" />
      </ZoneTemplate>
    </aspSample:MyEditorZone>
    <hr />
    <asp:Button ID="Button1" runat="server" Width="200"
      Text="Toggle ApplyVerb Enabled" OnClick="Button1_Click" />
    <br />
    <asp:Button ID="Button2" runat="server" Width="200"
      Text="Toggle CancelVerb Enabled" OnClick="Button2_Click" />
    <br />
    <asp:Button ID="Button3" runat="server" Width="200"
      Text="Display EditorParts Collection" OnClick="Button3_Click" />
    <asp:Label ID="Label1" runat="server" />
    <br />
    <asp:Button ID="Button4" runat="server" Width="200"
      Text="Toggle OKVerb Enabled" OnClick="Button4_Click" /> 
  </form>
</body>
</html>

The third part of the code example is a custom EditorZone class that shows how to work with a number of the EditorZoneBase class members. The custom class derives from EditorZone so that it can be used with a zone template in the declarative markup of the Web page. 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. This code example uses dynamic compilation; thus, you will notice that the Register directive near the top of the Web page does not reference an assembly file. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Server Control.

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 MyEditorZone : EditorZone
  {
    public MyEditorZone()
    {
    }
    protected override void OnDisplayModeChanged(object sender, 
      WebPartDisplayModeEventArgs e)
    {
      this.BackColor = Color.LightGray;
      base.OnDisplayModeChanged(sender, e);
    }
    protected override void OnSelectedWebPartChanged(object sender, 
      WebPartEventArgs e)
    {
      if (e.WebPart != null)
        e.WebPart.Zone.SelectedPartChromeStyle.BackColor = 
          Color.LightGreen;
      base.OnSelectedWebPartChanged(sender, e);
    }
    protected override void RenderBody(HtmlTextWriter writer)
    {
      writer.WriteLine("<hr />");
      base.RenderBody(writer);
    }
    protected override void RenderVerbs(HtmlTextWriter writer)
    {
      WebPartVerb[] verbs = new WebPartVerb[] { OKVerb, 
        CancelVerb, ApplyVerb };
      foreach (WebPartVerb verb in verbs)
      {
        if (verb != null)
          verb.Text += " Verb";
      }
      base.RenderVerbs(writer);
    }
  }
}

When you load the page in a browser, you can select Edit Mode from the drop-down list to switch to edit mode. 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. When the editing UI is visible, you can see the effects of the various declarative and programmatic uses of the EditorZoneBase 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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.