So in .NET we have...
<%=
<%: (new to .NET 4 - syntactic sugar for HTML encoding)
<%#
<%@
What exactly are these?
And are there more? Is there an exhaustive list of these and what they are anywhere? It's hard to know what to even search for - I didn't even hear of the term "code nugget blocks" 'til tonight when I discovered what <%: was.
They are called code nuggets. They provide ASP.NET framework instruction on how to process the statement within those symbols (<% %>). Until I knew its name, yep it was a little harder to ask about it in the community. Not sure of an 'exhaustive' list, but there are a couple more than you have specified though. Below are the list of other code nuggets and their uses and sample example.
Symbol -- Name -- Description -- eg (Format)
<%
--Standard code nugget--Indicates that the following statements are C# statements. Will have to follow C# syntax rules. eg.<%=
--Content code nugget--Similar to standard cn, difference being the returned result is directly inserted into response to the browser without having to useResponse.Write
. eg.(NOT RECOMMENDED, includes risk of html injection attack. If the input on the text box is something like "
< button type = submit > Submit</button >
", it will add a button to page. Of course there would be validation, but hope the point is clear.)<%:
--Encoded code nugget --Similar to <%=, but the response is HTML encoded. eg.Name is <%:textBox.Text%>
(whatever the input is on the text box, it is displayed. If the input is something like "< button type = submit > Submit</button >
", output would be "Name is<button type = submit> Submit</button>
".<%#
--Data-binding code nugget --Denotes a data-binding code nugget, used to refer to the current data object. Only usable with databind controls like repeater etc.<%#:
--Encoded data binding--Denotes an encoded data binding code nugget where the data-bound value is encoded. eg.(If encoded (
<%#:
) is used, it displays literals without interpretations, recommended.)"<%$
--Property code nugget--Used to refer to configuration value, such as those defined in Web.config.(Retrieves the value of cityMessage key from the config file.)
<%@
--Page directive--This is used to configure the Web Form (or control or master page, depending on the kind of directive. eg.All the above mentioned information and examples are from Adam Freeman's Pro ASP .NET 4.5 book, Chapter 12. Excellent book imo.
These
<%@
are directives. For an exhaustive list and documentation see MSDN.The
<%
are script blocks. Here is a good description in MSDNThe
<%#
block is used normally in bound controls. See this short article for more info.I'm not sure if all these WebForm tags have a proper collective name, but they should all be covered in ASP.NET Page Syntax.
There's another that's not on the list, ASP.NET Expressions: