Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


February 2000

Active Server Pages Takes the Bite out of Forms


RSS
Subscribe to Windows IT Pro | See More Active Server Pages (ASP) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

 See corrections to this article

ASP files usually contain regular HTML tags and VBScript programming commands. You place the programming commands within <% and %> brackets. ASP scripts work only on Web servers running IIS or machines running Peer Web Services (PWS) 3.0.

When a browser asks an IIS system to deliver a Web page with an HTML or HTM extension, the IIS system simply retrieves the file and transfers the file to the browser. In this case, the IIS system is nothing more than a file server.

In contrast, when a browser requests a file with an ASP extension, the IIS system checks the ASP file closely, finds the VBScript commands in the HTML code, and executes the VBScript commands. Running those commands usually modifies the HTML on the Web page; the resulting HTML is what the browser receives. IIS doesn't send the VBScript code (thus preventing people from easily figuring out how you set up your site), just the HTML that results from a combination of the original HTML and the text that added when the VBScript commands ran.

For example, consider the following one-line ASP file:

<p>The time is <%=time()%> </p>

Before transmitting this file, IIS sees the command =time(), which tells IIS to run the built-in VBScript time function (i.e., the function that returns the current time) and insert the result into the HTML. The resulting HTML that the user sees is

<p>The time is 03:16:32</p>

The ASP file for my solution has a large portion of VBScript at the beginning and a small amount of HTML at the end. The main job of the resulting Web page is to add the collected form text to feedback.txt, but the page also displays the name and email address that the user entered.

The first two statements in the ASP file tell IIS that the script is VBScript (other languages also work in ASP scripts) and that variables must be declared before they are used in the script. In general, you don't need to declare variables in VBScript. However, many people like to declare variables for organizational purposes and to decrease the probability of a mistyped variable name causing a bug. The Option Explicit statement tells IIS to enforce variable declaration.

The two Set statements let you manipulate files on the server. The first Set statement creates a file-system object, which activates the programming language's tools that allow file reads and writes. The second Set statement's parameters provide the name of the file you're working with (the default path is the \winnt\system32 directory), signal that you want to append data to the file (1 signifies read; 8 signifies append), and specify that the data must be in ASCII rather than Unicode. (For the append process to work, the file that you're appending must exist. Create an empty feedback.txt file before you try to execute the OpenTextFile method.)

The uname and email variables receive the user's name and email address. Request.form is a built-in VBScript method. To retrieve the user's information, you must pass the form's field names, "Username" and "UserEmail". You need to surround the form's field names (which must exactly match the names in the input type= statements in the HTML file) with double quotes.

The myfile.writeline method writes a string of characters to a file. In this case, the method writes the user's name and email address (separated by a space) to feedback.txt and starts a new line.

The myfile.close method closes the file. Finally, the last Set statement supports cleanup on the ASP server.

Use As You See Fit
I used this method because I've had trouble with FrontPage's server extensions and because I'm familiar with VB. However, my method might not work for you. VBScript isn't particularly fast, so you might not want to use it for a busy Web site. (My Software Conspiracy Web site has only about 10 visitors a day, so server performance wasn't a consideration.)

Although my example saves the data in a simple form, you might prefer to collect and save data in a Microsoft SQL Server database. If you're thinking about doing some ASP scripting, see Microsoft's Developer Network Web Workshop Web site (http://www.msdn.microsoft.com/ workshop/c-frame.htm#/workshop/server/default.asp) for links to ASP information. For additional ASP information, see SQL Server Magazine.

End of Article

   Previous  1  [2]  Next  


Reader Comments
Did anyone else who tried this sample get the following error?
Technical Information (for support personnel)

Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/addtext.asp, line 6
("Scripting.FileSystemObject")

I copied the text from the article verbatim.

I found the article very exciting because I have been trying to learn ASP for the past few weeks. I would really appreciate some clarification on this if possible.

Thank you.........I always read your magazine and learn new tricks all the time.

James R. Gregg February 05, 2000


Mark Minasi's Inside Out: "Active Server Pages Takes the Bite out of Forms" (February 2000) is a great article. What the article describes is exactly what I want to do. Will you send me the three files you reference in the article (form.html, addtext.asp, and feedback.txt)?
--­Cliff Airhart

Cliff Airhart April 27, 2000


<i>Here's a quick way to get form.html and addtext.asp: Go to Windows 2000 Magazine's online archive (http://www
.win2000mag.com/articles), scroll down and enter 7951 in the InstantDoc ID text box, and click Download the Code/Files in the Article Info box. Feedback.txt is just a blank file to start with, so you don't need to download it.
--­Mark Minasi</i>

Mark Minasi April 27, 2000


The article incorrectly states: "ASP scripts work only on Web servers running IIS or machines running Peer Web Services (PWS) 3.0." This is not accurate. Chili!soft has a product called Chili!ASP that allows ASP scripts to run on several flavors of windows. htttp://www.chilisoft.com

Dan M June 15, 2000


This message is more for James R. Gregg. You might try the following to "clean up" your issue.
1. Make sure you end up with three files (form.html, addtext.asp and feedback.txt)
2. Place "Feedback.txt" into your C: directory, the other two into a directory in your wwwroot/inetpub folder. I placed mine in a folder named "CODE"
3. Make sure you have properly "shared" that folder for ASP purposes.
4. Access the files by typing http://localhost/CODE/form.html
5. Enjoy playing with the app.
I think your issue may have arisen out of not having your "ASP" file properly named. If you do it in notepad, you must make sure when you save your file that you select "all files" and not "text files" from the drop down box at th ebottom, otherwise your file could get saved like this 'addtext.asp.txt" which your computer will not process.

Good Luck

James Taylor June 22, 2000


I, too, am very interested in this article as it describes exaclty what I require, but do not have the time (at the moment) to learn how to do it fully. However, upon running the page, despite copying exactly (at least I'm fairly sure), I get the following error:

Microsoft VBScript compilation error '800a0400'

Expected statement

/bpyoung/addtext.asp, line 14

option explicit

Bradley Young May 29, 2001


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Corrections to this Article:

  • Inside Out: “Active Server Pages Takes the Bite out of Forms” (February 2000) contains an Active Server Pages (ASP) file in which some lines of code wrap across two lines of text but don’t contain a continuation character sequence ( _). A correct version of the file is available for download at http://www.win2000mag.com/articles. Enter 7951 in the InstantDoc ID text box and click on the Zip file in the Article Info box.

Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Task Automation Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Will Your Next Generation Server System Meet Your Infrastructure Optimization Needs?

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement