views:

738

answers:

3

What is the official name for the "special" ASP.NET tags like this:

<%# %>
<%= %>
<%@ %>
<%$ %>

I can't seem to figure out the conceptual or well known name for these, so I'm having trouble searching for more info. As a bonus, can anyone give me a quick rundown of all of the possible "special tags" and what each one of them does (or point me to a resource)?

+4  A: 

No answer for your name question, but the MSDN "ASP.NET Page Syntax" page is pretty good (or rather, that's the top level page; the pages under it give more information).

EDIT: I had previously thought that <%# ... %> wasn't included in the list, but of course it is, under Data-Binding Expressions. Doh.

Jon Skeet
+30  A: 

The official name is "server-side scripting delimiters". Visual Studio 2008 syntax highlighting settings dialog calls these "HTML Server-Side Script".

  • <%@ %> is used for page level directives. (<%@Language="C#"%>)
  • <% %> is for inclusion of server-side code (<% x = x + 1; %>)
  • <%= %> is equivalent of Response.Write();
  • <%# %> is used for databinding in ASP.NET Controls.
  • <%$ %> is used for expression binding, usually with localized string resources. See http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx
  • <%-- --%> is used for server side comments.

There is also

<script runat="server">
</script>

which is the same as <% %>


Edit to add There's a new one coming in ASP.NET 4.0:

ssg
I believe there's a <%$ ... %> that databinds against appsettings/connection strings.
Simon Svensson
I haven't heard of that. Do you have a source?
ssg
They're called ASP.NET Expressions. See http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx
elo80ka
I wikified this, feel free to edit.
ssg
+2  A: 

I have always found this QuickStart page to be very useful, whenever I have a doubt about Server-side syntax. It details 8 different markup styles and provides illustrative examples of each one, in addition to explaining the pros and cons.

It doesn't mention the Page level directive, though, which IIRC is detailed elsewhere in the Quickstart.

Of course, this is relevant to ASP.NET 2.0.

Cerebrus