Wednesday, June 15, 2011

How to use ASP.NET Expression to set property in server control?


ASP.NET expressions are a declarative way set control properties based on information that is evaluated at run time.
<asp:Label id="label1" runat="server" text="<%$ Resources: Messages, ThankYouLabel %>" />
<asp:Literal runat="server" text="<%$ AppSettings: copyright %>"/>




ASP.NET Expression Builders

http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx



[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder {
    public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, 
       object parsedData, ExpressionBuilderContext context) {
        return new CodeSnippetExpression(entry.Expression);
    }
}
<compilation debug="true">
  <expressionBuilders>
    <add expressionPrefix="Code" type="Infinity.Web.Compilation.CodeExpressionBuilder"/>
  </expressionBuilders>
</compilation>
And to see it in action:
<asp:CheckBox id="chk1" runat="server" Text="<%$ Code: DateTime.Now %>" />

LINQ Cheat Sheet

Microsoft patches 34 vulnerabilities


http://www.net-security.org/secworld.php?id=11168