Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
EditorZone Class
Collapse the table of content
Expand the table of content

EditorZone Class

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)

'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class EditorZone _
	Inherits EditorZoneBase
'Usage
Dim instance As EditorZone
<asp:EditorZone />

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="vb" classname="DisplayModeMenuVB"%>

<script runat="server">

' Use a field to reference the current WebPartManager. 
Dim _manager As WebPartManager


Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) 
    AddHandler Page.InitComplete, AddressOf InitComplete

End Sub  


Sub InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) 
    _manager = WebPartManager.GetCurrentWebPartManager(Page)

    Dim browseModeName As String = WebPartManager.BrowseDisplayMode.Name

    ' Fill the dropdown with the names of supported display modes. 
    Dim mode As WebPartDisplayMode
    For Each mode In  _manager.SupportedDisplayModes
        Dim modeName As String = mode.Name
        ' Make sure a mode is enabled before adding it. 
        If mode.IsEnabled(_manager) Then 
            Dim item As New ListItem(modeName + " Mode", modeName)
            DisplayModeDropdown.Items.Add(item)
        End If 
    Next mode

End Sub  


' Change the page to the selected display mode. 
Sub DisplayModeDropdown_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
    Dim selectedMode As String = DisplayModeDropdown.SelectedValue

    Dim mode As WebPartDisplayMode = _manager.SupportedDisplayModes(selectedMode)
    If Not (mode Is Nothing) Then
        _manager.DisplayMode = mode
    End If 

End Sub  


Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
    DisplayModeDropdown.SelectedValue = _manager.DisplayMode.Name

End Sub 

</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="vb" %>
<%@ register tagprefix="uc1" 
  tagname="DisplayModeMenuVB" 
  src="displaymodevb.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    If EditorZone1.ApplyVerb.Enabled = True Then
      EditorZone1.ApplyVerb.Enabled = False 
    Else
      EditorZone1.ApplyVerb.Enabled = True 
    End If 
  End Sub 

  Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    EditorZone1.BorderWidth = 2
    EditorZone1.BorderColor = System.Drawing.Color.DarkBlue
  End Sub 

  Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = "<br />" 
    Dim part As EditorPart
    For Each part In EditorZone1.EditorParts
      Label1.Text += part.ID + "<br />" 
    Next part
  End Sub 

  Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs)
    EditorZone1.InstructionText = "My custom instruction text." 
  End Sub
</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:DisplayModeMenuVB 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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft