Monday, March 30, 2009

skmExpressionBuilders - A Suite of Custom Expression Builder Classes


An ASP.NET Web control's properties can be set in one of two ways: declaratively and programmatically. Declaratively setting a Web control's properties entails specifying
the property in the control's declarative syntax. For example, Web controls have their ID property set declaratively, like so:
<asp:WebControl runat="server" ID="ID" ... />. Properties can also be set programmatically in the ASP.NET
page's code-behind class. If you need to set a Web control's property to some dynamic value you may think you need to set it programmatically. However, this is not the case.
Expression builders make it possible to assign a dynamic value to a Web control property through the declarative syntax.


Last week's article, Using Expression Builders in ASP.NET, examined the ins and outs of expression
builders, their syntax, and how to use them in an ASP.NET page. ASP.NET ships with three built-in expression builder classes: AppSettingsExpressionBuilder,
which retrieves a value from the <appSettings> section defined in Web.config; ConnectionStringsExpressionBuilder, which retrieves a
value from the <connectionStrings> section; and ResourceExpressionBuilder, which retrieves a resource value. These expression builders can be
used in the declarative markup using syntax similar to the following: <asp:Label runat="server" id="Copyright" Text="<%$ AppSettings:CopyrightNotice
%>"
/>
.


With a little bit of elbow grease you can create your own custom expression builder classes. I've spent some time creating a handful of custom expression builder classes,
which I've packaged into a class library named skmExpressionBuilders. This article walks through the custom expression builders in this library and shows how to use them in
your ASP.NET application. Read on to learn more!

Read More >

0 comments:

Post a Comment

Copyright 2009 - Aspnetr.com

Site by Infonex.com