Home ASP.NET Hosting Dedicated Servers Contact Us
Announcements
Virtual Tiers
.NET Applications
XML Web Services
SQL Server Database
Web Traffic Statistics
Much More...
ASP.NET Web Site Hosting
Dedicated Servers
Windows 2003 Server
2.4 GHz Pentium 4
1024 MB RAM
80 GB Hard Drive
1000 GB/month
Fully Managed
Free Setup!
$268.00/month
Windows Dedicated Servers
Specialized Plans
10 or more Domains
Windows Services
Custom Plans
Windows Services
Learning & Support
About Us



Using ASP.NET Render Blocks



Learn More about Server Intellect



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" %>
<html>
<head>
</head>

<body>

<center>

<form action="form.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 %>

</form>

</center>

</body>
</html>


Important: 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.

ASP.NET page developers can utilize <% %> code blocks to dynamically modify HTML output much as they can today with ASP. For example, the following sample demonstrates how <% %> code blocks can be used to interpret results posted back from a client.

<%@ Page Language="VB" %>

<html>
<head>
</head>

<body>

<center>

<form action="form.aspx">

<h3> Name: <input name="Name" type=text value="<%= Request.QueryString("Name")%>">

Category: <select name="Category" size=1>

<%
Dim I As Integer
Dim Values(2) As String
Values(0) = "psychology"
Values(1) = "business"
Values(2) = "popular_comp"

For I = 0 To Values.Length - 1
%>

<% If (Request.QueryString("Category") = Values(i)) %>
<option selected>
<% Else %>
<option>
<% End If %>
<%=Values(i)%>
</option>

<% Next %>

</select>
</h3>

<input type=submit name="Lookup" value="Lookup">

<p>

<% If (Not Request.QueryString("Lookup") = Nothing) %>

Hi <%= Server.HtmlEncode(Request.QueryString("Name")) %>, you selected: <%=Request.QueryString("Category") %>

<% End If %>

</form>

</center>

</body>
</html>


Important: While <% %> code blocks provide a powerful way to custom manipulate the text output returned from an ASP.NET page, they do not provide a clean HTML programming model. As the sample above illustrates, developers using only <% %> code blocks must custom manage page state between round trips and custom interpret posted values.