Creating a Custom ExpressionBuilder in ASP.NET 2.0
page 1 of 6
Published: 24 Jan 2007
In this article Bilal Haidar will explain to you what ExpressionBuilders are in ASP.NET 2.0 and how to create a custom ExpressionBuilder to read an XML settings file.
by Bilal Haidar
Average Rating: 
Views (Total / Last 10 Days): 34891/ 64


A new feature in ASP.NET 2.0 has been introduced, the ExpressionBuilder. The ExpressionBuilder allows declarative binding for control properties for data that is coming either from the ConnectionStrings and AppSettings section of the web configuration file or from the web application resource files.

The way you add a declarative expression to a control property is as follows:

Listing 1

<asp:Label ID="lblPath" runat="server" Text='<%$ AppSettings: WebPath %>' />

As you can see above, we have assigned the Text property of the Label control a declarative expression which shall retrieve the WebPath key from the AppSettings section of the web.config file of the ASP.NET web application.

When the page is being parsed, if the parser passes by such a declarative expression, it will create a new instance of the AppSettingsExpressionBiulder and then evaluate the expression. Evaluating the expression in this case is by taking the right hand side of the declarative expression which is WebPath and then retrieving the value of that key from the web configuration file. Finally, it binds the value of that key to the Text property of the Label control.

In this article we will cover the different built-in ExpressionBuilders that shipp with the ASP.NET 2.0 and build a custom ExpressionBuilder to bind the ASP.NET controls to a separate XML settings files.

View Entire Article

User Comments

Title: Enquiry   
Name: Bharat Bhushan
Date: 2010-11-03 1:31:44 AM
I got the use of expression prefix but i want to know
about type attributes of add tag of expressionbuilders
Title: Expression Builder - Excellent!   
Name: Matt, UK
Date: 2009-10-19 5:48:20 PM

Fantastic article. Downloaded the sample and it works like a dream. Many thanks for this!
Title: Expression Builder   
Name: Unknown
Date: 2008-12-12 7:24:13 AM
Really very good example with all the description in short language

Thanks a lot and It's easy to understand...
Title: Custom Expression   
Name: S.Y.
Date: 2007-09-27 4:34:17 PM
The custom expression works great but is there a way to set this from the properties expression editor? It only accepts RESOURCES, APPSETTINGS and CONNECTIONSTRINGS. Is it possible to have the XmlSettings part of the expression type? Wanted to view the actual literal at the design time.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-15 4:15:52 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search