Slide 10.d: Writing your first ASP.NET page
Slide 10.f: Adding simple code to a page (cont.)
Home

Adding Simple Code to a Page


ASP.NET provides syntax compatibility with existing ASP pages. This includes support for <% %> code render blocks that can be intermixed with HTML content within an .aspx file. These code blocks execute in a top-down manner at page render time. The below example demonstrates how <% %> render blocks can be used to loop over an HTML block (increasing the font size each time):

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <body>
  <center>
   <form action="intro2_vb.aspx" method="post">
    <h3> Name: <input id="Name" type=text>
     Category:
     <select id="Category" size=1>
      <option>psychology</option>
      <option>business</option>
      <option>popular_comp</option>
     </select>
    </h3>
    <input type=submit value="Lookup"> 
    <p>
     <% Dim I As Integer
      For I = 0 to 7 %>
      <font size="<%=I%>"> Welcome to ASP.NET </font> <br />
     <% Next %> 
    </p>
   </form>
  </center>
 </body>
</html>



Unlike with ASP, the code used within the above <% %> blocks is actually compiled—not interpreted using a script engine. This results in improved runtime execution performance.