ASPNL logo (1 kb)
Thursday, November 20, 2008

powered by


Microsoft ASP.NET Connections
Member of ASP Guild
<< previous | index | next >>

My first ASP page: Hello world!

An ASP page consists of script and possibly HTML. The script is placed between
<% and %> delimiters, and can be embedded in between the HTML.

To make pages dynamic, you have to be able to send text (with ASP) to the browser. You can do this with the Response.Write statement. The value you give this function will be sent to the browser. The best way to show this is with an example:

helloworld1.asp
<HTML>
<BODY>
<%
'Write to the browser
Response.Write("Hello world!")
%>
</BODY>
</HTML>


Before the line that really does something, there's a line with a ' character in front of it (shown in green). This is a comment, so you'll get a better idea of what is happening. Especially for bigger pieces of code it is wise to add comments. As you can see the code is embedded in between the HTML. This doesn't have to be in one place, you can do this in several places. Like this, for example:

helloworld2.asp
<HTML>
<HEAD>
<TITLE>
<%
Response.Write("Example: Hello world!")
%>
</TITLE>
</HEAD>
<BODY>
<%
Response.Write("Hello world!")
%>
</BODY>
</HTML>


In the sample above you don't just write something in the browser-screen, but also in the titlebar.

It is not wise to have too much HTML and ASP interspersed. That causes ASP to make a lot of so called context switches, which makes the script slower.

Response.Write

Response.Write consists of two parts. The part before the period is the Response object, which is being used for interaction with the user. The second part is a method of the Response object. In this case the Write method, which sends text to the browser. Other methods will be discussed in other lessons.

<< previous | ^ to top | index | next >>
copyright 2000-2002 ASPNL