Inline Expressions in ASP.NET Web Forms
<%= ... %>
displaying expression
- display the result of an expression
- will not work in a server control attribute
<%= DateTime.Now() %>
<%# ... %>
data-binding expression
- bind a server control property to a data source...
- ...when the control's
DataBind
method is called Three techniques:
- Call
Eval()
for one-way, read-only binding - Call
Bind()
for two-way, read-write binding - Call any publicly available code and and display its return value.
- Call
<%# MyMethodOrProperty() %>
<%$ ... %>
expression builder
- set values based on configuration or resource files
- e.g. read web.config settings
<%$ AppSettings: someKey %>
<%-- ... -- %>
server-side comments block
- comment out code.
<%-- This is a comment. --%>
<%@ ... %>
directive expression
- provide page and user control settings
<%@Page Language="C#" ... />
<% ... %>
embedded code blocks
- designed for backward compatibility
- avoid
See Also
Introduction to ASP.NET inline expressions in the .NET Framework