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

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.

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.

What are these tag names <% and <%=? [duplicate]

This question already has answers here:
ASP.NET "special" tags
(5 answers)
Closed 10 years ago.
I tried searching SO, but I guess it doesn't like the syntax <%= in the query text so if this is a duplicate, I'll delete it.
My question is, what are the actual names of the following tags? What would i call them if describing them to someone else
<%
<%=
and if you know them
<%#
<%#
<% scriptlets
<%= expression
<%# expression
<%# directives
EDITED
Imagine like this
1. Whatever you write within <% %> are placed in some 'process' function
2. Whatever you write inside <%# %> are placed at class level
3. You can just write expressions inside <%= %> imagine something is written to print Response.Write (we also do not write ';' at the end eg. <%= x+5 %>) and <%# %> is same as <%= %> but the difference is the way they function internally
NOTE: This is just for your understanding and not taken from any source.
<% is a "classic-asp" tag which is used to write server-side code. You can name it scriptlets.You can use it in .net platform in c# also.
<%= is not really a tag. It is used to write something.
%# directives is used for directives

<%# %> vs <%= %> [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
ASP.NET “special” tags
What is the difference between <%# ... %>, <%= ... %> and <%$ ... %>?
I couldn't find anything information about this. It's impossible to find "<%=" using a search engine.
Do these tags have a name?
<%= ... %> is generally equivalent to Response.Write(...)
it cannot be used in a control attribute that is runat="server"
<%: ... %> (as of .NET v4.0) is an html encoded version of <%= %> (as #Eric mentions)
<%# ... %> is used in data-binding context for Bind, Eval or Output (as #Ray mentions)
<%$ ... %> is used in the context of a control attribute with runat="server" (google "expression builder" also have a look at making a general purpose 'Code' expression builder. it is evaluated when the attribute/Parameter is required by the control.
<%# %> will attempt to databind to a data source, using the Bind() function. This makes it a two-way function (read and write).
<%= %> will make the data read-only.
<%# %> is evaluated during data binding. It does not necessarily require Eval() or Bind() and Matthew suggested - I use it frequently to display plain text in a repeater control.
<%= %> is evaluated as the page renders. It is equivalent to calling Response.Write().
<%# %> can ONLY be used in data-binding context.
<%= %> expects a string value which it will then include in the output stream. So either a string variable or a method which returns a string. Anything else will cause an error.
I found some good information that clarifies the terminology for your future google searches:
http://authors.aspalliance.com/aspxtreme/aspnet/syntax/aspnetpagesyntax.aspx
Code Render Blocks:
<% inline code %>
A shortcut for HttpResponse.Write:
<%=inline expression %>
Data Binding Expressions:
<%# databinding expression %>
In a property:
<tagprefix:tagname property = "<%# databinding expression %>" runat="server" />
Server-side comments, such that they do not appear in the client's page source:
<%-- commented out code or content --%>

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.

Tags in 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?

Resources