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

AppearanceEditorPart Class

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

Provides an editor control that enables end users to edit several user interface (UI) properties on an associated WebPart control. This class cannot be inherited.

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

public sealed class AppearanceEditorPart : EditorPart
public final class AppearanceEditorPart extends EditorPart
public final class AppearanceEditorPart extends EditorPart

The AppearanceEditorPart class is an editor control that derives from the EditorPart class, and is used to edit properties that affect the appearance of an associated WebPart or other server control.

The AppearanceEditorPart control enables end users to edit several UI properties of a WebPart control. The type of control that appears in the page to edit each property value is listed in the adjacent cell of the following table.

Property

Control used to edit property

Title

A TextBox control is used to set the text for the title.

ChromeType

A DropDownList control is used to select what type of title-and-border option is used.

Direction

A DropDownList control is used to select the direction that content flows on the page.

Height

A TextBox control is used to set a number for the height, and a DropDownList control is used to select the units.

Width

A TextBox control is used to set a number for the height, and a DropDownList control is used to select the units.

Hidden

A CheckBox control is used to indicate whether the control is hidden.

The AppearanceEditorPart control becomes visible only when a Web Parts page is in edit mode, and when a specific WebPart control has been selected for editing. The AppearanceEditorPart control, like all other EditorPart controls, resides in an EditorZone zone.

NoteImportant:

An EditorZone zone can contain only EditorPart controls, and EditorPart controls cannot be placed in any other type of zone.

The AppearanceEditorPart class has a minimal set of properties. The Title property is used to get or set a string that is displayed as a title when the control is visible. The DefaultButton property sets the inherited property from the Panel control, so that the default control that receives the focus within the AppearanceEditorPart control is the same as the default in the base Panel control.

The AppearanceEditorPart class also has two important methods. The SyncChanges method overrides the base method from the EditorPart class. This method is critical because it enables getting the property values from the WebPart control it is editing and assigning them to the fields in the editor control. The ApplyChanges method is also important, because it takes the values set by the user in the editing controls, and updates those property values on the control being edited.

In most cases the AppearanceEditorPart control should be used in page persistence format by declaring an <asp:appearanceditorpart> element inside a <zonetemplate> element, which is in turn contained by an <asp:editorzone> element on a Web page.

To edit other properties and behavior of WebPart controls, you can use the other EditorPart controls supplied with the Web Parts control set. These controls include the BehaviorEditorPart, the LayoutEditorPart, and the PropertyGridEditorPart. The supplied EditorPart controls should provide most editing features required to edit WebPart controls, but you can also create a custom editor control by inheriting from the EditorPart class. For a code example, see the EditorPart class overview topic.

NoteNote

To improve accessibility, the AppearanceEditorPart control is rendered within a <fieldset> element. The <fieldset> element groups the related set of controls used for editing in the AppearanceEditorPart control, and it facilitates tabbed navigation among those controls for both visual (such as ordinary Web browsers) and speech-oriented user agents (such as screen-reading software).

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.

TopicLocation
How to: Set the Display Mode of a Web Parts PageBuilding ASP .NET Web Applications
How to: Set the Display Mode of a Web Parts PageBuilding ASP .NET Web Applications

The following code example demonstrates how to declare an AppearanceEditorPart control on a Web page, and enable it to edit several UI properties of a WebPart control. The code example has four parts:

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

  • A Web page that contains an EditorZone control and an AppearanceEditorPart control, along with a reference to a custom WebPart control.

  • A class that contains a custom WebPart control.

  • An explanation of how the example works when you load the page 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 the Web page. It contains a declarative reference to an EditorZone control, with a child <zonetemplate> element that contains declarative references to an AppearanceEditorPart control. Also, the page references the custom WebPart control, using a Register directive for the assembly, and the <aspSample:TextDisplayWebPart> element for the control.

<%@ page language="c#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenu" 
  Src="DisplayModecs.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="TextDisplayWebPartCS" %>

<html>
  <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" 
            Title="Edit TextDisplayWebPart Properties" />
        </ZoneTemplate>      
      </asp:EditorZone>
    </form>
  </body>
</html>

The third part of the code example is a custom WebPart class named TextDisplayWebPart, which is referenced in 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. For a walkthrough that demonstrates how to compile, 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 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;
      }
    }

  }
}

When you load the page in a browser, you can select Edit Mode in the Display Mode drop-down control to switch to edit mode. 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 UI is visible, you can see the AppearanceEditorPart control. If you make some changes in the editing UI and click the Apply button, you can use the Display Mode drop-down list to return the page to browse mode and see the full effect of the editing changes.

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.Panel
         System.Web.UI.WebControls.WebParts.Part
           System.Web.UI.WebControls.WebParts.EditorPart
            System.Web.UI.WebControls.WebParts.AppearanceEditorPart
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.