Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | ASP | Q5810 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.