How can I get a variable from a different code code expression than the block in which the variable was declared?

Can someone explain how asp.Net works below?

I have 2 separate asp.Net code block expressions in aspx markup with html content in between (span element in the example below).

In the first block of code, there is an “i” as an increment variable for the for loop.

Then the code block is cut out with the html content.

And another code code expression is open, but as I see it, I can achieve the variable "i" that was declared in the previous block of code.

So how does asp.net handle -compiles- block-code snippets declared in markup? Does it check half-colons and generate some anonymous methods that will end up with a lot of Response.Write calls in last place?

Thank,

<p>
   <%for (int i = 0; i < 30; i++)
     {
         Response.Write("Some text here");

         %>

     <span> ______________________________ </span> <%--So how this line is processed 
                                                    by ASP.Net so that it is embedded 
                                                    in the for loop as Response.Write 
                                                    method parameter?--%>

   <%
         Response.Write(i*(i+1));

         Response.Write("<br />");
     }%>
</p>
+3
2

# ASPX. ACTUAL {} , , , HTML .

, , % HTML/#.

+1

, , Response.Write . -.

<span> "" #; # - ASP ( <span> ).

0

Source: https://habr.com/ru/post/1771320/


All Articles