ASP Scripting Basics

Learn the basics of scripting with the Active Server Pages (ASP) language.

Michael Otey

August 31, 1999

2 Min Read
ITPro Today logo in a gray background | ITPro Today


Active Server Pages (ASP) scripting combines HTML with VBScript, JScript or any other ActiveX compliant scripting language. Due in part to the widespread popularity of Visual Basic (VB), VBScript, which is a subset of VB, is probably the most common scripting language used in ASP applications. VBScript shares the syntax and object-naming conventions of its more-capable progenitor. However, ASP pages are more than just listings of ActiveX script. You build ASP pages by combining VBScript and HTML. Inside the pages, you use special script tags to insert VBScript into the HTML. The code in Listing A shows the shorthand form of the tag format that you can use to demark VBScript in ASP pages.

The way ASP scripts generate output is also different from the method that standard VB uses. You can direct output to the user either with the = symbol or by using the Response object’s Write method. The following lines of code illustrate both ways you can direct information out to the browser from an ASP script.

<%= "This writes line one"Response.Write("This writes line two")%>

The code in Listing B creates two simple HTML text boxes that let a Web client enter a user ID and password. Not surprisingly, the name of the user ID field is userid, and the name of the password field is password. After filling out these fields, the Web user clicks Submit to send the form to its form handler. The form handler is a generic technique that you can use in all HTML development environments. If you’re developing in Visual InterDev (VID), you can take advantage of VID’s design-time controls, which let you visually define event handlers for your Web application. In this case, the form handler is an ASP page named loginrsp.asp. The source code for the loginrsp.asp contains the following VBScript:

<%Dim sUserDim sPwd  'Retrieve form informationsUser = Request.Form("userid") sPwd = Request.Form("password")%>

You can use the Request object’s Form method to access the values that users enter into the text boxes on the previous form. The script supplies the name of the HTML inout object to the Form method. To retrieve the value from the object, you must give the Form method the exact name of the object on the original page. In this case, the ASP script retrieves the values for the text boxes named userid and password.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like