home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / MS_DEV / VID / SERVER / ASF / DATA.Z / atumd1.asp < prev    next >
Text File  |  1996-10-22  |  11KB  |  175 lines

  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  2.  
  3. <html>
  4.  
  5. <head>
  6. <title>Module 1: Creating ASP Pages</title>
  7.  
  8. </head>
  9.  
  10. <BODY BGCOLOR="#FFFFFF"><FONT FACE="ARIAL,HELVETICA">
  11. <h1><a name="ChapTop">Module 1: Creating ASP Pages</a></h1>
  12. <p>In this module, you will learn some ActiveX basics by creating your own ASP pages (.asp files). You will find the example files 
  13. you are to use in these lessons in the Tutorial\Lessons directory in your Active Server Pages samples directory (\InetPub\ASPSamp\Tutorial by 
  14. default). Save the files you create in the Tutorial\Lessons directory as well. 
  15. <hr>
  16. <h2><a name="CreatingaSimpleActiveXPage">Lesson 1: Creating a Simple ASP Page</a></h2>
  17. <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. 
  18. 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!” 
  19. 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>
  20. <p><img src="images/ovrvuart.gif" alt="Creating ASP pages" align=bottom width=413 height=140></p>
  21. <p>The following HTML commands create a simple page with the words “Hello World!” in a large font:</p>
  22. <FONT FACE="COURIER"><pre><HTML> 
  23. <FONT SIZE=7> 
  24. Hello World!<BR> 
  25. </FONT> 
  26. </HTML> </pre></FONT>
  27. <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 
  28. page, the line will be displayed several times. 
  29. <p>
  30. Alternatively, you could use ASP to generate this content in a more efficient manner.
  31.  
  32. <h3><A NAME="Createandsaveapage">Create and save a page</A></h3>
  33. <ol>
  34. <li>Start a text editor (such as Notepad) or a word processor (such as Microsoft® Word). Position the text editor window and the 
  35. browser window so that you can see both.<br>
  36.  
  37. <li>Type the following HTML tag at the beginning of the file: <FONT FACE="COURIER"><CODE><HTML> </CODE></FONT>
  38.  
  39. <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 
  40. file in text format if you are using a word processor, including WordPad. ASP  pages must have the .asp extension so 
  41. that ASP knows to process the page. <br>
  42.  
  43. <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 %> 
  44. </CODE></FONT>
  45. <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 
  46. script command. Any text following the closing delimiter is simply displayed as HTML text in the browser. This script 
  47. command begins a VBScript loop that controls the number of times the words "Hello World" are displayed. The first time 
  48. 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 
  49. the counter exceeds 7. </p>
  50.  
  51. <li>Press ENTER, then type the following line: <FONT FACE="COURIER"><CODE><FONT SIZE=<% = i %>> </CODE></FONT>
  52. <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 
  53. 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 
  54. within an HTML tag. </p>
  55.  
  56. <li>Press ENTER, then type the following lines: <FONT FACE="COURIER"><pre>Hello World!<BR> 
  57. <% Next %>
  58. </HTML></pre></FONT>
  59. <p>The VBScript <strong>Next</strong> expression repeats the loop (until the counter exceeds 7). </p>
  60. </li>
  61. <li>Save your changes. Be sure to save your file in text format and be sure the file name extension is .asp. 
  62.  
  63. <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 
  64. happens, replace the .txt extension with the .asp extension before you click <strong>Save</strong>. </p>
  65.  
  66. <li>Exit your text editor. A browser might not be able to read an HTML page that is open in a text editor. 
  67.  
  68. <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>. 
  69.  
  70. <p>You should see a Web page with “Hello World!” displayed five times, each time in a larger font size.
  71.  
  72. </ol>
  73. <p>Congratulations! You have completed your first ASP page. As you have learned, the process of creating an ASP 
  74. 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 
  75. 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 
  76. previously opened page).</p>
  77. <hr>
  78. <h2><a name="CreatinganHTMLForm">Lesson 2: Creating an HTML Form</a></h2>
  79.  
  80. <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 
  81. JScript directly into an HTML file to process the form. ASP reads the scripts, performs the commands, and returns the 
  82. results to the Web browser.
  83.  
  84. <p>In this lesson, you will create an ASP page that processes the data a user submits by way of an HTML form.
  85.  
  86. <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 
  87. <Strong>Submit </Strong> button to send your data to the server.
  88.  
  89. <hr>
  90. <!--#include file="script1.asp" --><hr>
  91. <h4>Create the Form</h4>
  92. <p>We have created a form to request user information; you can find it in the file Form.htm in the Lessons directory:
  93.  
  94. <FONT FACE="COURIER"><pre><HTML>
  95. <HEAD><TITLE>Order</TITLE></HEAD>
  96.  
  97. <BODY>
  98. <H2>Sample Order Form</H2>
  99. <P>
  100. Please provide the following information, then click Submit:
  101.  
  102. <FORM METHOD="POST" ACTION="response.asp">
  103. <P>
  104. First Name: <INPUT NAME="fname" SIZE="48">
  105. <P>
  106. Last Name: <INPUT NAME="lname" SIZE="48">
  107. <P>
  108. Title: <INPUT NAME="title" TYPE=RADIO VALUE="mr">Mr.
  109. <INPUT NAME="title" TYPE=RADIO VALUE="ms">Ms.
  110.  
  111. <P><INPUT TYPE=SUBMIT><INPUT TYPE=RESET>
  112. </FORM>
  113.  
  114. </BODY>
  115.  
  116. </HTML></pre></FONT>
  117. <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 
  118. <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 
  119. variable and value pairs submitted by a form. </p>
  120. <h3><A NAME="CreatetheASPResponsePage">Create the ASP Response Page</A></h3>
  121. <ol>
  122. <li>Use your text editor to open the Response.asp file in the Lessons directory (\InetPub\ASPSamp\Tutorial\Lessons by default). 
  123.  
  124. <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
  125. to process the information from the form. 
  126.  
  127. </li>
  128. <li>Search for the words "Tutorial Lesson" and replace the entire line with the following code: <FONT FACE="COURIER"><pre><% Title = Request.Form("title") 
  129. </pre></FONT>
  130.  
  131. <p>Your form transmits three types of information to ASP:
  132.  
  133. <ul>
  134. <pre>
  135. <li>fname
  136. <li>lname
  137. <li>title
  138. </pre>
  139. </ul>
  140.  
  141. 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 
  142. Object Reference</a>). To retrieve information from the Request object, you type the following: 
  143. <FONT FACE="COURIER"><code>Request.<em>collection-name</em> ("<em>property-name</em>")</code></FONT>.
  144. 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.  
  145.  
  146. <li>Insert the following lines of script following the line you inserted in Step 2: <FONT FACE="COURIER"><pre>LastName = Request.Form("lname")
  147. If Title = "mr" Then %>  
  148. Mr. <% = LastName %>  
  149. <% ElseIf Title = "ms" Then %> Ms. <% = LastName %> 
  150. </pre></FONT>
  151. <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 
  152. 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 
  153. expression <FONT FACE="COURIER"><code><%=<em>variable-name</em>%></code></FONT>: 
  154.  
  155. <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 %>
  156. <% = Request.Form("fname") & " " & LastName %>
  157. <% End If %> 
  158. </pre></FONT>
  159.  
  160. <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>
  161.  
  162. <li>Save Response.asp and exit the text editor. Be sure your text editor does not replace the .asp extension.
  163.  
  164. <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> 
  165.  
  166. </ol>
  167.  
  168. <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>. 
  169. <hr>
  170. <p align=center><a href="/iasdocs/aspdocs/sdklegal.htm"><em>© 1996 Microsoft Corporation. All rights reserved.</em></a></p>
  171. </FONT>
  172. </body>
  173.  
  174. </html>
  175.