Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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?

like image 724
John B Avatar asked Jun 16 '09 20:06

John B


2 Answers

Custom Expressions are handy if you care about ViewState (you should). See TRULY Understanding ViewState.

like image 26
Pavel Chuchuva Avatar answered Sep 28 '22 22:09

Pavel Chuchuva


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).

like image 60
M4N Avatar answered Sep 28 '22 21:09

M4N