ExpressionBuilder Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Evaluates expressions during page parsing.

Namespace:   System.Web.Compilation
Assembly:  System.Web (in System.Web.dll)

public abstract class ExpressionBuilder


Initializes a new instance of the ExpressionBuilder class.


When overridden in a derived class, returns a value indicating whether the current ExpressionBuilder object supports no-compile pages.


Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodEvaluateExpression(Object, BoundPropertyEntry, Object, ExpressionBuilderContext)

When overridden in a derived class, returns an object that represents an evaluated expression.


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetCodeExpression(BoundPropertyEntry, Object, ExpressionBuilderContext)

When overridden in a derived class, returns code that is used during page execution to obtain the evaluated expression.


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodParseExpression(String, Type, ExpressionBuilderContext)

When overridden in a derived class, returns an object that represents the parsed expression.


Returns a string that represents the current object.(Inherited from Object.)

The ExpressionBuilder class is the base class for expression builders, such as the AppSettingsExpressionBuilder class, that create code expressions during page parsing.

Expression builders parse declarative expressions and create code to retrieve values bound to a control property. In no-compile scenarios, an expression builder that supports a no-compile feature evaluates the expression during run time.

When the page parser encounters an expression that is delimited with the string <%$ %>, it creates an expression builder for the expression based on the prefix in the string. The prefix is the portion of the string that is to the left of the colon (:). For example, when the parser encounters the string <%$ ConnectionStrings:MessageDB %>, it creates a ConnectionStringsExpressionBuilder object. Prefixes are associated with expression builders in the Web.config file in the ExpressionBuilders section.

The right side of the declarative expression is passed to the expression builder for evaluation. Override the GetCodeExpression method to generate code that will be compiled with the page.

If you want the custom expression builder to be active on pages that are not compiled, you must also override the EvaluateExpression method to return an object that represents the results of the expression. You also must override the SupportsEvaluate property to indicate that the custom expression builder does support no-compile pages.

You can define a set of properties and methods for selecting and evaluating an expression that is associated with a control property at design time by implementing an expression editor. The editor is marked on the expression builder through class-level metadata. For more information, see ExpressionEditor.

Notes to Inheritors:

When you inherit from the ExpressionBuilder class, you must override the GetCodeExpression method.

The following code examples demonstrate how to build a custom expression builder by implementing the ExpressionBuilder abstract class. This implementation of ExpressionBuilder returns an evaluated statement that is passed to the expression. To run this example, you must first register the custom expression builder in the Web.config file. The first code example demonstrates how to register the custom expression builder in the Web.config file.

              <add expressionPrefix="MyCustomExpression"

The second code example demonstrates how to reference the expression in an .aspx file.

<asp:Label ID="Label1" runat="server" 
Text="<%$ MyCustomExpression:Hello, world! %>" />

The third code example demonstrates how to develop a customized expression builder by deriving from ExpressionBuilder. To run this code example, you must place the class in the App_Code folder.

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top