Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q5810 How should I mix ASP and HTML on the same page?

You are here: irt.org | FAQ | ASP | Q5810 [ previous next ]

If you place ASP and HTML together as in example 1, below, there will be a greater amount of switching back and forth between interpreters by your web server, and therefore the page will probably be slightly slower for a single user. Mulitply that by hundreds of hits and it will definately be slower.

Much better is to 'encapsulate' your code as in example 2, writing any HTML using the Response.Write method rather than switching out of ASP and back in again:

<%
' *** EXAMPLE 1 ***
%>
<html>
<head>
</head>
<body>
<p>
<% response.write "The current date is : " & Now() %
>
</p>
<p>
<table>
<% for i = 1 to 50
	totalSum = totalSum + i
%>
<tr>
<td>
<% response.write i%>
</td>
</tr>
<% Next %>
</table>
<p>
The total sum of 1 - 50 is : <% response.write totalSum %
>
</p>
</body>
</html>


<%
' *** EXAMPLE 2 ***
%>
<html>
<head>
</head>
<body>
<p>
<%
response.write "The current date is : " & Now()
response.write "</p>"
response.write "<p>"
response.write "<table>"
for i = 1 to 50
	totalSum = totalSum + i
	response.write "<tr><td>" _
	& i _
	& "<td></tr>"
Next
response.write "</table>"
response.write "</p>"
response.write "The total sum of 1 - 50 is : " & totalSum
%>
</p>
</body>
</html>

Feedback on 'Q5810 How should I mix ASP and HTML on the same page?'

©2018 Martin Webb