Home page
 
 Home 
 ASP 
 PHP 
 SQL 
 HTML 
 JavaScript 
 Search 
 Contact 
 
Search
or browse popular tags
ASP Tutorial
Subscription

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

Your First ASP Page

Print

Before we can begin please make sure you have installed PWS or IIS on your system as you need one of these web servers to be able to view a page containing ASP (just opening the page in your web browser by double-clicking on the page will NOT work). If you are unsure on how to install PWS or IIS please read the tutorial How to install ASP on your own computer.

Right, now we are going to create your first ASP page. In this tutorial we will display the classic 'Hello World' text in a web page as well as the time and date on the web server.

An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file can also contain  server scripts, surrounded by the delimiters  <% and  %>. Server scripts are  executed on the server, and can contain any expressions, statements, procedures, or operators valid for the scripting language you prefer to use.

As ASP is going to be displayed as part of a web page we first need to create an HTML web page. Open your favourite text editor and type the following.

<html>
<head>
<title>My First ASP Page</title>
</head>
<body bgcolor="white" text="black">

Next we can begin writing some ASP. The following code declares a variable to hold the text 'Hello World'. Remember that anything after the ' is commented out and thus not processed.

<%
'Dimension variables
Dim strMessage
'Place the value Hello World into the variable strMessage
strMessage = "Hello World"

Once the variable has a value we can now display the contents of the variable in the HTML by using the ASP 'Response.Write' command to write output to a browser:

'Write the contents of the variable strMessage to the web page
Response.Write (strMessage)

Next we shall use the 'Response.Write' command  and the VBScript function 'Time()' to display the server time on the HTML page.

'Write line break into the web page
Response.Write ("<br>")
'Write the server time on the web page using the VBScript Time() function
Response.Write ("The time on the server is: " & Time())

Now we should close the server side script tag as we have finished using ASP in this part of the web page.

'Close the server script
%>

Finally we need to finish the HTML web page by closing the body tag and the HTML tag.

</body>
</html>

To test this script on your own computer you should remember that when you installed PWS or IIS an 'Inetpub' folder should have been created on your harddrive with the sub folder 'wwwroot'. Locate this folder and inside it create a new folder called 'asp_examples'.

Save the file as my_first_asp_page.asp in your 'c:\inetpub\wwwroot\asp' folder. Next open your browser and type 'http://localhost/asp/my_first_asp_page.asp'.

Congratulations, you have now created your first dynamic ASP web page.




Tags:

Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments





Copyright © 2005-2014             www.WebCheatSheet.com All Rights Reserved.