What are and how the following statements work on Web Forms pages:%%,% #%, and%:%

4

I do not know what they are, nor how to call them. Are tags, statements? What are they?

In practice, I noticed some features.

  • <% %> This statement accepts executable code, but does not return anything to the webpage.

  • <%# %> This statement also accepts executable code, but is apparently limited to an expression and does not execute non-return methods. It also does not return anything to the web page.

  • <%: %> This statement is identical to the above statement but has its value returned to the webpage.

  • asked by anonymous 18.02.2015 / 04:07

    1 answer

    4

    <%% >

      

    This statement accepts executable code, but does not return anything to the webpage.

    It depends. In fact, that's not quite what you put in.

    This is the inherited markup for Classic ASP. It simply performs some imperative instruction, not necessarily writing in HTML.

    Now, I can perfectly write in HTML using the following form:

    <% Response.Write("Estou escrevendo no HTML!"); %>
    

    <% #% >

      

    This statement also accepts executable code, but it is apparently limited to an expression and does not execute non-return methods. It also does not return anything to the webpage.

    That's not quite it. This statement is for you to do bindings ( binding ) within another ASP.NET tag. For example:

    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("Coluna")  %>' Width="70" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    In this case, <%# Eval("Coluna") %> mocks data to <asp:Image> .

    <%:% >

      

    This statement is identical to the above statement, but has its value returned to the webpage.

    Actually <%: %> is equivalent to <%= %> , with the additional character encoding suitable for HTML .

    There are other notations not mentioned in the question that can be found here .

        
    18.02.2015 / 05:41