<% %> in ASP.NET (embedded code blocks)

后端 未结 5 1404
醉话见心
醉话见心 2021-01-30 13:57

I understand what these signify in the markup of the aspx pages ... but I don\'t not know the full power they can be used for or even the name to denote these special directives

5条回答
  •  自闭症患者
    2021-01-30 14:33

    The MSDN documentation calls them embedded code blocks. You can put pretty much any code you would place in code-behind files and the server will execute them before serving your pages to browsers.

    Directive is the name given to one particular type of code block, the one most commonly seen at the top of ASP.NET pages to give the compiler information about your ASP.NET pages. They are delimited by <%@ and %>.

    The language of the code blocks is the same one as specified in the directive block. A quick example:

    <%@ Page Language="C#" %>
    
    
      
        

    <% string hello = "Hello world!"; Response.Write(hello); %>

      <% for (int i = 1; i <= 5; ++i) { %>
    1. <% Response.Write("Item #" + i); %>
    2. <% } %>

提交回复
热议问题