Tags in ASP.NET - asp.net

What's the difference between <%= Something %> and <%# Something %>?
Are there any other modifiers of this kind?
Duplicate
What is the difference between the <%# and <%= opening tags?

See these questions:
What is the difference between the <%# and <%= opening tags?
In ASP.NET what are the differant ways to inline code in the .aspx?

Related

Inline server code in client page [duplicate]

This question already has an answer here:
Asp.net server-side code block explanations
(1 answer)
Closed 8 years ago.
Not a difficult question but i can't seem to find a decent answer to it:
inline server code in client page,
what are the usage/different of these:
<% %>
<%# %>
<%= %>
are there any more?
<% %>
Is used for executing arbitrary blocks of code on the server. Usually some type of control statement is place inside of them.
<%= %>
Writes content out to the response stream, similar to Response.Write().
Making something like (below) possible.
<table>
<%
for (int i = 0; i < n; i++)
%><tr><td><%= i %></td></tr><%
%>
</table>
The <% %> tag is used for code blocks. The tag doesn't output anything in itself. Example:
<% int answer = 42; %>
The <%# %> tag is used for data binding.
The <%= %> tag is used for value output. The tag evaluates the expression and the result is written to the page. Example:
<%= answer %>
There is also the <%: %> tag, which is the same as the <%= %> tag except that the output is HTML encoded.
<%$ %> is used for Resources.

Web Forms Inline Code Begin Tags

I just wan to to know why these different begin tags exist, if there are still more and if they can be used interchangeably:
<%# Do.Something() %>
<%= Do.Something() %>
...
The tags do different things. For example <%= %> will write the result of the expression within the tags to the output, while <%# %> will use data-binding expressions to reference data from a data source. A fuller explanation can be found at http://weblogs.asp.net/ahmedmoosa/archive/2010/10/06/embedded-code-and-inline-server-tags.aspx

how to Embedded Code Blocks in ASP.NET Web Pages?

where we use <%# %> <%= %> <%# %> etc.
what else asp tags can be added in asp.net web pages?
<%%> is short hand for:
<script runat="server">
</script>
Anyting inside the <% and %> is server side code.
The other variants are also shortcuts:
<%#%> is a page directrive
<%=%> is short for Response.Write
<%:%> is short for Response.Write, adding html encoding (introduced with .NET 4.0)
<%#%> is a binding expression
This page is a good reference to all these.
<%# %> - page directives, Register control
<%= %> - for the server code
<%# %> - for the eval kind of function its also for the server code

What is the difference between <%= %> syntax and <%# %> in asp.net?

What is the difference between <%= %> syntax and <%# %> in asp.net?
Here is a complete reference for all of these "inline tags," with links to MSDN for each type:
http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx
<%= %> is basically used for string while <%# %> is used for data binding.
See following
http://support.microsoft.com/kb/307860
As compared to the <%= version, <%# is treated specially in parameters. It adds a data binding handler and sets the property at data bind time. That's why <%# does work in parameters and why it picks up the value at data bind time.

In ASP.Net, what is the difference between <%= and <%# [duplicate]

This question already has answers here:
Closed 14 years ago.
In ASP.Net, what is the difference between <%= x %> and <%# x %>?
See this question:
When should I use # and = in ASP.NET controls?
Summary from those answers:
There are a several different 'bee-stings':
<%# - Page/Control/Import/Register directive
<%$ - Resource access and Expression building
<%= - Explicit output to page, equivalent to <% Response.Write( ) %>
<%# - Data Binding. It can only used where databinding is supported, or at the page level if you call Page.DataBind() in your code-behind.
<%-- - Server-side comment block
<%: - Equivalent to <%=, but it also html-encodes the output.
<%# is data binding expression syntax.
<%= resolves the expression returns its value to the block (Embedded code block reference) - effectively shorthand for <% Response.Write(...); %>
<%# is the databinding directive, <%= is a shortcut for "Response.Write"
<%= x %> is shorthand for Response.Write()
<%# x %> indicates a databind.
<% %> indicates server-executable code.

Resources