This documentation is archived and is not being maintained.

ExpressionEditor Class

Defines a set of properties and methods for evaluating an expression that is associated with a control property at design time and to provide an expression editor sheet to the visual design host for use in the expression editor dialog box. This class is abstract.

Namespace:  System.Web.UI.Design
Assembly:  System.Design (in System.Design.dll)

public abstract class ExpressionEditor

A visual designer host, such as Visual Studio 2005, uses the ExpressionEditor class to present custom expression editor sheets to the user, and then evaluate the selected expression for design-time rendering.

When you browse the Expressions property for a control in the design-time Properties grid, the visual designer displays a dialog box to set expressions for a control property. You can select the expression type based on a list of expression prefixes. When you select an expression prefix from the list, the visual designer uses the associated ExpressionEditor and ExpressionEditorSheet objects to set, evaluate, and convert the expression string based on the syntax for that type of expression. The visual designer sets the expression for the associated control property, and then uses the evaluated expression result to assign control property values that are rendered on the design surface.

The static GetExpressionEditor methods get the expression editor that is associated with a particular expression prefix or expression builder. The ExpressionPrefix property for an ExpressionEditor object returns the configured expression prefix. The EvaluateExpression method evaluates an input expression string. The GetExpressionEditorSheet method returns the ExpressionEditorSheet implementation that is used to prompt for the custom expression properties in the expressions dialog box.

Typically, to support a new expression type at design time, you define a unique expression prefix and provide custom ExpressionBuilder and ExpressionEditor implementations. Optionally, you can provide a custom ExpressionEditorSheet implementation that defines properties that are used to form the expression in the expressions dialog box.

The expression prefix identifies the custom expression type and associates an expression with the expression builder and expression editor. When custom expressions are parsed in a page, the expression prefix is used to create instances of the associated ExpressionBuilder and ExpressionEditor classes. To associate an expression prefix with an expression builder and expression editor, apply the ExpressionEditorAttribute and ExpressionPrefixAttribute attributes to the custom ExpressionBuilder class and configure the expression prefix for an expression builder in the expressionBuilders element in the Web configuration file. The prefix is not required, but highly recommended.

Notes to Inheritors:

The following steps are required in deriving a custom ExpressionEditor class:

  • Override the EvaluateExpression method to evaluate the custom expression type at design time.

  • Optionally, override the GetExpressionEditorSheet method to return a custom class that defines properties that are combined to form the custom expression.

  • Apply the ExpressionEditorAttribute attribute on the ExpressionBuilder class declaration to associate the custom expression builder with the derived expression editor class.

For example, the ResourceExpressionEditor class derives from the ExpressionEditor class and provides an implementation for evaluating and associating a resource string reference with a control property at design time. The ResourceExpressionBuilder class is associated with the expression prefix Resources and the ResourceExpressionEditor implementation. The GetExpressionEditorSheet method returns a ResourceExpressionEditorSheet, which defines the individual properties that form a resource reference expression.

The following code example demonstrates how to derive from the ExpressionEditor class to define a custom expression editor.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.CodeDom;
using System.Configuration;
using System.Web.UI.Design;
using System.Web.Compilation;

namespace ExpressionEditorSamples.CS
    public class CustomAppSettingsBuilder : AppSettingsExpressionBuilder
        // Use the built-in AppSettingsExpressionBuilder class, 
        // but associate it with a custom expression editor class.


    public class CustomAppSettingsEditor : System.Web.UI.Design.ExpressionEditor
        public override object EvaluateExpression(string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider)
            KeyValueConfigurationCollection customSettings = null;

            if (serviceProvider != null)
                IWebApplication webApp = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));
                if (webApp != null)
                    Configuration config = webApp.OpenWebConfiguration(true);
                    if (config != null)
                        AppSettingsSection settingsSection = config.AppSettings;
                        if (settingsSection != null)
                            customSettings = settingsSection.Settings;


            if (customSettings != null)
                return customSettings[expression];

            return expression;


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