ASP.NET 2.0 ships with three ExpressionBuilders:
AppSettingsExpressionBuilder: Used
to retrieve values from the AppSettings section of the web configuration file.
ConnectionStringsExpressionBuilder:
Used to retrieve values from the ConnectionStrings section of the web
configuration file.
ResourceExpressionBuilder: Used to
retrieve values from the resource files, whether Local or Global resources.
AppSettingsExpressionBiulder
The .NET Framework creates a new instance of the
AppSettingsExpressionBuilder when you are using a declarative expression that
is accessing a key from the AppSettings section of the web configuration file.
The example clarifies how to access the AppSettings section
declaratively.
Listing 2
<asp:Label ID="lblPath" runat="server" Text='<%$ AppSettings: WebPath %>' />
As explained above, the code is retrieving the WebPath key
from the AppSettings section and binding it to the Text property of the Label
server control.
ConnectionStringsExpressionBuilder
Most of you have seen such a code:
Listing 3
<asp:SqlDataSource ID="SqlDataSource1"
runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT * FROM [CMS_ACL]"></asp:SqlDataSource>
This is a SqlDataSource control that handles the connection
with a database and retrieves data according to the SelectCommand. You can see
the existence of the ConnectionString property that has been assigned a
declarative expression to retrieve the connection string from the ConnectionStrings
section of the web configuration file.
ResourceExpressionBuilder
ASP.NET 2.0 made building Multilanguage web applications an
easy task to do when they introduced the App_LocalResources and
App_GlobalResources special folders to hold the local and global resource files
respectively. Accessing both Global and Local resources can be done through the
explicit declarative expression by specifying the Resources keyword on the left
hand side of the declarative expression.
We have created a local resource file called Default.aspx.resx
placed in the App_LocalResources folder. In a web form named Default.aspx we
have placed the following Label server control.
Listing 4
<asp:Label ID="lblResourceKey" runat="server" Text="<%$ Resources:KeyFromResource %>" />
As you can see, the keyword Resources have been used on the
left hand side of the expression and on the right hand side the key name to
retrieve its values has been specified.