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.