Search code examples
c#asp.netvb.netexpressionbuilder

When are ASP.NET Expression Builders most useful?


I saw an example of using Expression Builders, and creating your own Custom Expression Builder Classes here:

https://web.archive.org/web/20210513211719/http://aspnet.4guysfromrolla.com/articles/022509-1.aspx

However, I fail to see the value in using this approach. It doesn't seem much easier than programmatically setting values in your code behind.

As far as I can tell, the only thing you can do with them is set properties. Maybe they would be useful for setting defaults on certain controls?

Can anyone shed light on where this ASP.NET feature becomes powerful?


Solution

  • We are using a custom expression builder to localize our application. E.g. the markup looks like this:

    <asp:LinkButton Text="<%$ Str:SomeString %>" ... />
    

    The expression builder reads a string with the ID SomeString from a resource file (taking into account the current user's language preferences) and assigns it to the Text property of the LinkButton.

    This is quite flexible: we can add languages by simply copying a resource file into the application directory. And if a customer wants to have a different text for that linkbutton, he just adds his custom string to the resource files and changes the string-ID in the expression builder (without having to change the code-behind).