This documentation is archived and is not being maintained.

PropertyGridEditorPart Class

Provides an editor control that enables end users to edit custom properties on an associated WebPart or server control. This class cannot be inherited.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class PropertyGridEditorPart : EditorPart
<asp:PropertyGridEditorPart />

The PropertyGridEditorPart provides a generic user interface (UI) that enables users to edit custom properties on WebPart and server controls placed in WebPartZoneBase zones. In contrast, the other EditorPart controls, such as the AppearanceEditorPart and BehaviorEditorPart controls, edit only existing, UI-oriented properties from the WebPart class.

Just as there are tool-oriented zones in the Web Parts control set (for details, see the ToolZone class overview), there are tool-oriented part controls, and each of these must reside in a corresponding type of tool zone. These kind of controls in the Web Parts control set have two distinguishing characteristics:

  • They are helper controls that enable end users to personalize the controls that form the primary UI of a page in a Web Parts application.

  • They are visible only in certain page display modes.

The PropertyGridEditorPart control is a special control, and it becomes visible only when a Web page is in edit mode, and when a specific WebPart or server control has been selected by a user for editing. The PropertyGridEditorPart control, like all other EditorPart controls, must reside in an EditorZone zone on the page.

Important noteImportant Note:

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

The PropertyGridEditorPart control provides an editing UI for properties that are marked in the source code with the WebBrowsable attribute (from the WebBrowsableAttribute class). When a property is marked with this attribute, a PropertyGridEditorPart control creates the editing UI based on the type of the property, and uses a PropertyDescriptor object if needed to convert the value in each editing control to the type of the property. You can also add other attributes that help the PropertyGridEditorPart control to display the editing UI. The WebDisplayName attribute (from the WebDisplayNameAttribute class) allows you to specify the text for the label that appears with each control in the editing UI. The WebDescription attribute (from the WebDescriptionAttribute class) allows you to specify a string that appears as a ToolTip for each control in the editing UI.

The controls created to edit properties of various types are listed in the following table.

Property type

Control created to edit the property



Int, Float, Unit





DropDownList (contains the list of enumerated values)



The PropertyGridEditorPart class has a Title property, which is used to get or set the visible title text for the control. There is also a protected Display property, which determines whether the control is displayed when the page enters edit mode.

The PropertyGridEditorPart class also has two important methods, ApplyChanges and SyncChanges, which it inherits from the EditorPart class and overrides. The methods are critical because they enable getting and setting the property values between the field values of the editor control and the properties on the WebPart control being edited.

Because the PropertyGridEditorPart control allows you to edit only custom properties, you will need the other EditorPart controls in the Web Parts control set to edit the appearance, layout, and behavior of WebPart controls. The other controls include the BehaviorEditorPart, the LayoutEditorPart, and the AppearanceEditorPart controls. These EditorPart controls should provide most editing features required to edit WebPart controls, but if necessary, you can also create a custom editor control by inheriting from the EditorPart class. For a code example, see the EditorPart class overview topic.


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


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.

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 a PropertyGridEditorPart 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 a PropertyGridEditorPart control, along with a reference to a custom WebPart control.

  • A class that contains the 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 a declarative reference to a PropertyGridEditorPart control. The page references the custom WebPart control, using a Register directive for the assembly, and the <aspSample:UserInfoWebPart> element for the control.

<%@ page language="c#" %>
<%@ register TagPrefix="uc1" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Assembly="UserInfoWebPartCS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
    Button1.Visible = false;
    TextBox1.Visible = false;

  private static String editControlTitle;

  protected void Button1_Click(object sender, EventArgs e)
    editControlTitle = Server.HtmlEncode(TextBox1.Text);
    PropertyGridEditorPart1.Title = editControlTitle;

  protected void PropertyGridEditorPart1_Init(object sender, EventArgs e)
    if (editControlTitle != null)
      PropertyGridEditorPart1.Title = editControlTitle;

  protected void PropertyGridEditorPart1_PreRender(object sender,
    EventArgs e)
    Button1.Visible = true;
    TextBox1.Visible = true;

<html xmlns="" >
  <head runat="server">
      User Information WebPart with EditorPart
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server"  />
      <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server" >
        <PartTitleStyle BorderWidth="1" 
          Font-Names="Verdana, Arial"
          BackColor="LightBlue" />
            title = "User Information WebPart"
            BackColor="Beige" />          
      <hr />
      <asp:Button ID="Button1" runat="server" 
        Text="Update EditorPart Title" 
        OnClick="Button1_Click" />
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:EditorZone ID="EditorZone1" runat="server">
          <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" 
            Title="Edit Custom Properties"
            OnInit="PropertyGridEditorPart1_Init" />   

The third part of the code example is a custom WebPart class named UserInfoWebPart, which is referenced in the Web page. Notice that the various properties that contain information about a user are all marked with the WebBrowsable attribute. This enables the PropertyGridEditorPart control to provide the UI for editing those properties. The properties are also marked with a WebDisplayName attribute, to specify the text of the label that appears next to each control in the editing UI.

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 Web Server Control.

Security noteSecurity Note:

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

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
    Level = AspNetHostingPermissionLevel.Minimal)]
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class UserInfoWebPart : WebPart
    HttpServerUtility server = HttpContext.Current.Server;
    private String _userNickName = "Add a nickname.";
    private String _userPetName = "Add a pet name.";
    private DateTime _userSpecialDate = DateTime.Now;
    private Boolean _userIsCurrent = true;
    private JobTypeName _userJobType = JobTypeName.Unselected;
    public enum JobTypeName
      Unselected = 0,
      Support = 1,
      Service = 2,
      Professional = 3, 
      Technical = 4,
      Manager = 5,
      Executive = 6
    Label NickNameLabel;
    Label PetNickNameLabel;
    Label SpecialDateLabel;
    CheckBox IsCurrentCheckBox;
    Label JobTypeLabel;

    // Add the Personalizable and WebBrowsable attributes to the   
    // public properties, so that users can save property values   
    // and edit them with a PropertyGridEditorPart control.
    [Personalizable(), WebBrowsable, WebDisplayName("Nickname")]
    public String NickName
        object o = ViewState["NickName"];
        if (o != null)
          return (string)o;
          return _userNickName;        

      set { _userNickName = server.HtmlEncode(value); }

    [Personalizable(), WebBrowsable, WebDisplayName("Pet Name")]
    public String PetName
        object o = ViewState["PetName"];
        if (o != null)
          return (string)o;
          return _userPetName;        

      set { _userPetName = server.HtmlEncode(value); }

    [Personalizable(), WebBrowsable(), WebDisplayName("Special Day")]
    public DateTime SpecialDay
        object o = ViewState["SpecialDay"];
        if (o != null)
          return (DateTime)o;
          return _userSpecialDate;


      set { _userSpecialDate = value; }

    [Personalizable(), WebBrowsable(), WebDisplayName("Job Type"), 
      WebDescription("Select the category that corresponds to your job.")]
    public JobTypeName UserJobType
        object o = ViewState["UserJobType"];
        if (o != null)
          return (JobTypeName)o;
          return _userJobType;

      set { _userJobType = (JobTypeName)value; }

    [Personalizable(), WebBrowsable(), WebDisplayName("Is Current")]
    public Boolean IsCurrent
        object o = ViewState["IsCurrent"];
        if (o != null)
          return (Boolean)o;
          return _userIsCurrent;

      set { _userIsCurrent = value; }

    protected override void CreateChildControls()

      NickNameLabel = new Label();
      NickNameLabel.Text = this.NickName;

      PetNickNameLabel = new Label();
      PetNickNameLabel.Text = this.PetName;

      SpecialDateLabel = new Label();
      SpecialDateLabel.Text = this.SpecialDay.ToShortDateString();

      IsCurrentCheckBox = new CheckBox();
      IsCurrentCheckBox.Checked = this.IsCurrent;

      JobTypeLabel = new Label();
      JobTypeLabel.Text = this.UserJobType.ToString();

      ChildControlsCreated = true;


    private void SetControlAttributes(WebControl ctl)
      ctl.BackColor = Color.White;
      ctl.BorderWidth = 1;
      ctl.Width = 200;

    protected override void RenderContents(HtmlTextWriter writer)
      writer.Write("Pet Name:");
      writer.Write("Special Date:");
      writer.Write("Job Type:");

When you load the page in a browser, select Edit Mode in the Display Mode drop-down list control to switch to edit mode. You can click the verbs menu (the downward arrow) in the title bar of the User Information WebPart control, and click Edit to edit the control. When the editing UI is visible, you can see the PropertyGridEditorPart control. Notice that a control is rendered for each of the properties of the UserInfoWebPart class, based on the type of the property. 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.


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