I’m developing a front-end part of an application right now, and a question came to my mind.
What is the difference between asp.net special tags:
<%= %> <%@ %> <%# %>
And if exists another special tag please describe its function.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
-
<%=prints the raw value of the expression within.
This syntax can cause XSS vulnerabilities and should not be used. -
<%:prints and HTML-escapes the value of the expression within. -
<%#is like<%=, but is used for data-binding -
<%executes a block of code and ignores and return values -
<%@is used for directives likePageorImports.
Method 2
Check the below site Once..You will get an idea
These are some useful special tags
- <% %> An embedded code block is server code that executes during the page’s render phase. The code in the block can execute programming statements and call functions in the current page class. http://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx
- <%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx
- <%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx
- <%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx
- <%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx
- <%– –%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx
- <%: %> Like <%= %> But HtmlEncodes the output (new with Asp.Net 4). http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx
Method 3
- <%= %> Code Render Block – For evaluate inline expressions
- <%@ %> Directive Syntax – Usualy for linking the codebehind and a
asp.net page. - <%# %> Data binding
You can find more information at:
http://msdn.microsoft.com/en-us/library/fy30at8h(v=vs.85).aspx
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0