Posted by Gabriel Perez on: 9/28/2008 12:00:00 AM
Setting a property of a server tag is pretty standard stuff:
<asp:TextBox ID="TextBox1" runat="server" Text="My name is Gabriel" />
Now, what if you want to use a class to set the value?
<asp:TextBox ID="TextBox1" runat="server" Text='<%= DateTime.Now %>' />
This will give you an error like this:
Server tags cannot contain <% ... %> constructs
If you ever need to solve this kind of problem I found a very interesting solution in the Infinites Loop Blog
It’s a very clever solution to use the Expression Builders, introduced in the Asp.Net 2.0 feature, to let you execute your custom code within the server tags.