Creating a Custom ExpressionBuilder in ASP.NET 2.0
page 1 of 6
Published: 24 Jan 2007
Abstract
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
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 12287/ 164

Introduction

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

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 1 and 6 and type the answer here:

User Comments

Title: Custom Expression   
Name: S.Y.
Date: 9/27/2007 4:34:17 PM
Comment:
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 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/5/2008 12:32:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search