Difference between special tags asp.net

旧时模样 提交于 2019-12-01 07:30:04

问题


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.


回答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 like Page or Imports.




回答2:


Check the below site Once..You will get an idea

http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx

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




回答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



来源:https://stackoverflow.com/questions/18154310/difference-between-special-tags-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!