<% %>
This statement accepts executable code, but returns nothing to the web page.
It depends. Actually that’s not quite what you put.
This is the markup inherited from ASP Classic. It simply executes some imperative instruction, not necessarily writing in HTML.
Now, I can perfectly write in HTML using as follows:
<% Response.Write("Estou escrevendo no HTML!"); %>
<%# %>
This statement also accepts executable code, but appears to be limited to an expression and does not execute no-return methods. It also returns nothing to the web page.
That’s not quite it. This statement is for you to carry out data moorings (Binding) within another ASP.NET tag. For example:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("Coluna") %>' Width="70" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In this case, <%# Eval("Coluna") %>
makes the data binding to <asp:Image>
.
<%: %>
This statement is identical to the above statement, but has its value returned to the web page.
In fact <%: %>
is equivalent to <%= %>
, with the added character encoding suitable for HTML.
There are other notations not mentioned in the question that can be found here.