<h1><a name="ChapTop">Module 1: Creating ASP Pages</a></h1>
<p>In this module, you will learn some ActiveX basics by creating your own ASP pages (.asp files). You will find the example files
you are to use in these lessons in the Tutorial\Lessons directory in your Active Server Pages samples directory (\InetPub\ASPSamp\Tutorial by
default). Save the files you create in the Tutorial\Lessons directory as well.
<hr>
<h2><a name="CreatingaSimpleActiveXPage">Lesson 1: Creating a Simple ASP Page</a></h2>
<p>The best way to learn about ASP pages is to write your own. To create an ASP page, use a text editor to insert script commands into an HTML page. Saving the page with an .asp file extension tells ASP to process the script commands.
To view the results of a script, simply open the page in a Web browser. In this lesson, you will create the popular Hello World!
script by copying HTML and ASP scripting commands from this tutorial page into a text editor. You can then view the script's output with your browser. </p>
<p><img src="images/ovrvuart.gif" alt="Creating ASP pages" align=bottom width=413 height=140></p>
<p>The following HTML commands create a simple page with the words Hello World! in a large font:</p>
<FONT FACE="COURIER"><pre><HTML>
<FONT SIZE=7>
Hello World!<BR>
</FONT>
</HTML> </pre></FONT>
<p>Suppose you wanted to repeat this text several times, increasing the font size with each repetition. You could repeat the font tags and HTML text, giving it a different font size with each repetition. When a browser opens the HTML
page, the line will be displayed several times.
<p>
Alternatively, you could use ASP to generate this content in a more efficient manner.
<h3><A NAME="Createandsaveapage">Create and save a page</A></h3>
<ol>
<li>Start a text editor (such as Notepad) or a word processor (such as Microsoft® Word). Position the text editor window and the
browser window so that you can see both.<br>
<li>Type the following HTML tag at the beginning of the file: <FONT FACE="COURIER"><CODE><HTML> </CODE></FONT>
<li>Save the document as <FONT FACE="COURIER"><code>Hello.asp</code></FONT> in the Lessons directory (\InetPub\ASPSamp\Tutorial\Lessons by default). Be sure to save the
file in text format if you are using a word processor, including WordPad. ASP pages must have the .asp extension so
that ASP knows to process the page. <br>
<li>Start a new line after the <FONT FACE="COURIER"><code><HTML></code></FONT> tag and type the following code: <FONT FACE="COURIER"><CODE><% For i = 3 To 7 %>
</CODE></FONT>
<p>Script commands are enclosed within <FONT FACE="COURIER"><code><%</code></FONT> and <FONT FACE="COURIER"><code>%></code></FONT> characters (also called <em>delimiters</em>). Text within the delimiters is processed as a
script command. Any text following the closing delimiter is simply displayed as HTML text in the browser. This script
command begins a VBScript loop that controls the number of times the words "Hello World" are displayed. The first time
through the loop, the counter (<FONT FACE="COURIER"><code>i</code></FONT>) is set to 3. The second time the loop is repeated, the counter is set to 4. The loop is repeated until
the counter exceeds 7. </p>
<li>Press ENTER, then type the following line: <FONT FACE="COURIER"><CODE><FONT SIZE=<% = i %>> </CODE></FONT>
<p>Each time through the loop, the font size is set to the current value of the counter (<FONT FACE="COURIER"><code>i</code></FONT>). Thus, the first time the text is displayed, the
font size is 3. The second time, the font size is 4. The last time, the font size is 7. Note that a script command can be enclosed
within an HTML tag. </p>
<li>Press ENTER, then type the following lines: <FONT FACE="COURIER"><pre>Hello World!<BR>
<% Next %>
</HTML></pre></FONT>
<p>The VBScript <strong>Next</strong> expression repeats the loop (until the counter exceeds 7). </p>
</li>
<li>Save your changes. Be sure to save your file in text format and be sure the file name extension is .asp.
<p>Some text editors automatically change the file extension to .txt when you choose <Strong>Text Format </Strong> in the <Strong>Save</Strong> dialog box. If this
happens, replace the .txt extension with the .asp extension before you click <strong>Save</strong>. </p>
<li>Exit your text editor. A browser might not be able to read an HTML page that is open in a text editor.
<li>To view the results of your work (after which you can return to this Tutorial by clicking the Back button in your browser), point your browser to <a href="http://localhost/aspsamp/tutorial/lessons/hello.asp">http://localhost/aspsamp/tutorial/lessons/hello.asp</a>.
<p>You should see a Web page with Hello World! displayed five times, each time in a larger font size.
</ol>
<p>Congratulations! You have completed your first ASP page. As you have learned, the process of creating an ASP
page is simple. You can use any text editor to create HTML content and ASP commands (enclosed in <FONT FACE="COURIER"><code><%</code></FONT> and ,<FONT FACE="COURIER"><code>%> </code></FONT> delimiters) as
long as you give your files an .asp file extension. To test a page and see the results, you open the page in a Web browser (or refresh a
previously opened page).</p>
<hr>
<h2><a name="CreatinganHTMLForm">Lesson 2: Creating an HTML Form</a></h2>
<p>A common use of Internet and intranet server applications is to process a form submitted by a browser. Previously, you needed to write a program to process the data submitted by the form. With ASP, you can embed scripts written in VBScript or
JScript directly into an HTML file to process the form. ASP reads the scripts, performs the commands, and returns the
results to the Web browser.
<p>In this lesson, you will create an ASP page that processes the data a user submits by way of an HTML form.
<p>To see how the server page works, fill in the form below. You can use the TAB key to move around the form. Click the
<Strong>Submit </Strong> button to send your data to the server.
<hr>
<!--#include file="script1.asp" --><hr>
<h4>Create the Form</h4>
<p>We have created a form to request user information; you can find it in the file Form.htm in the Lessons directory:
<FONT FACE="COURIER"><pre><HTML>
<HEAD><TITLE>Order</TITLE></HEAD>
<BODY>
<H2>Sample Order Form</H2>
<P>
Please provide the following information, then click Submit:
<p>Like all forms, this one sends the data to the Web server as pairs of variables and values. For example, the name the user types in the
<FONT FACE="COURIER"><code>First Name</code></FONT> text box is assigned to the variable named <FONT FACE="COURIER"><code>fname</code></FONT>. ASP provides built-in objects that you can use to access the
variable and value pairs submitted by a form. </p>
<h3><A NAME="CreatetheASPResponsePage">Create the ASP Response Page</A></h3>
<ol>
<li>Use your text editor to open the Response.asp file in the Lessons directory (\InetPub\ASPSamp\Tutorial\Lessons by default).
<p>This file contains the HTML page that the Web server returns to the client browser. You will add ASP script commands to this page
to process the information from the form.
</li>
<li>Search for the words "Tutorial Lesson" and replace the entire line with the following code: <FONT FACE="COURIER"><pre><% Title = Request.Form("title")
</pre></FONT>
<p>Your form transmits three types of information to ASP:
<ul>
<pre>
<li>fname
<li>lname
<li>title
</pre>
</ul>
ASP stores information submitted by way of HTML forms in the <b>Forms</b> collection of the <b>Request</b> object. (You can learn more about objects and forms in <a href="guide/asgall.htm">Active Server Pages Scripting Guide</a> and <a href="ref/obj/introbj.htm">Active Server Pages
Object Reference</a>). To retrieve information from the Request object, you type the following:
Thus, Request.Form ("title") retrieves <FONT FACE="COURIER"><code>mr</code></FONT> or <FONT FACE="COURIER"><code>ms</code></FONT>, depending on the value the user submitted.
<li>Insert the following lines of script following the line you inserted in Step 2: <FONT FACE="COURIER"><pre>LastName = Request.Form("lname")
If Title = "mr" Then %>
Mr. <% = LastName %>
<% ElseIf Title = "ms" Then %> Ms. <% = LastName %>
</pre></FONT>
<p>The VBScript <strong>If...Then</strong> statement performs two different actions depending on the value of <FONT FACE="COURIER"><code>Title</code></FONT>. If <FONT FACE="COURIER"><code>Title</code></FONT> is <FONT FACE="COURIER"><code>mr</code></FONT>, the user
will be addressed as " Mr." If <FONT FACE="COURIER"><code>Title</code></FONT> is <FONT FACE="COURIER"><code>ms</code></FONT>, the user will be addressed as "Ms." You display the value of a variable by using the
<li>To display both the first and last name if the user did not choose a title, insert the following lines of script following the line you inserted in Step 3:<FONT FACE="COURIER"><pre><% Else %>
<% = Request.Form("fname") & " " & LastName %>
<% End If %>
</pre></FONT>
<p>The ampersand (<FONT FACE="COURIER"><CODE>& </CODE></FONT>) joins the values of the variables into one string. The <strong>End If</strong> statement ends the conditional expression.</p>
<li>Save Response.asp and exit the text editor. Be sure your text editor does not replace the .asp extension.
<li>To verify that the form you've created works (after which you can return to this Tutorial by clicking Back in your browser), point your browser to <a href="http://localhost/aspsamp/tutorial/lessons/form.htm">http://localhost/aspsamp/tutorial/lessons/form.htm</a>
</ol>
<p>Congratulations! You have activated your first HTML form. The world of Active server components awaits you in <a href="atumd2.asp">Module 2: Using Active server components</a>.