ASP.NET has a numerous server side tag syntax, here is my attempt to explain them all:
<%
This is your basic tag for including server side code on a webform or view (MVC).
Example:
<%
string testVar = “Hello”;
if (testVar == “Hello”)
{
//do stuff
}
%>
<%=
This is the equivalent of Response.write, this tag has been around since the classic asp days.
Example:
<%= Request.QueryString(“Variable”) %>
<%#
Used for outputting databound data via Eval and other databinding methods.
Example:
<asp:DataList ID=”dlPhotos” runat=”server”>
<ItemTemplate>
<%# Eval(“Filename”) %>
</ItemTemplate>
</asp:DataList>
<%—
Server side commenting, comparable to <!— —> in HTML.
Example:
<%— <asp:Literal ID=”lcName” runat=”server” /> —%>
<%@
Used for directive statements, usually found atop your page.
Example:
<%@ Import Namespace=”My.Namespace” %>
<%:
Very similar to <%= but performs an HTML encode on the data.
Example:
<%: Html.Image(“~/images/test.png”) %>