views:

53

answers:

1

I'm not even sure i'm calling this the right thing. I'm just starting to get into ASP.Net and of course i'm starting to see syntax like <% "Code here" %>. So far i've seen <%: %>, <%= %>, <%# %>. Of course google doesn't like these symbols for searching so searching for help is futile :). Maybe this type of syntax is back from classic ASP (which i never used)? I don't know if there are any others than what i listed. Does anyone have a good link or can write up a good explanation. I also think it used in XML literals for vb.net. I also think its associated with certain functions like the "Eval" function.

+2  A: 

To be short,

  • <%# %> is used for data binding (for example in a ListView where you want to specify how elements must be displayed on a page). If this.Page.DataBind() (or control-level binding) is not called, nothing will be displayed.

  • <%= %> is used to display any string. <% %> on the other hand would let you to do any stuff you want, but you must use Response.Write() to output something.

  • <%: %> is a new feature in .NET Framework 4.0 which does the same thing as <%= %>, but encodes output to be displayed as HTML.

This is called inline tags, so searching for "asp.net inline tag" may give you additional info.

MainMa
thanks a bunch mainma....is there any others that i didn't list?
je5
@je5: yes, there are: `<%-- --%>` comment syntax, `<%@ %>` directives and the very strange `<%$ %>` used for expressions.
MainMa