HOME | SITEMAP | SUPPORT | HELP
DOMAIN MANAGE/BACKROOM | BILLING
4Domains Web Hosting and Domain Registration
Account Login   WebMail   Live Chat

Web Hosting

Domain Names

Domain Auction

Solutions

Home > Ntguide > Chapter5




Previous Section
Table of Contents
Next Section

5 Active Server Pages (ASP)

Active Server Pages (ASP) is where the true power of the Windows NT hosting environment is released. ASP allows the web site to deliver data based on the users input received from a HTML form, information from our data store, client side cookies, and/or text files that allow the server to deliver customized the pages "on the fly" before sending it to the requestor. There are hundreds of functions that do just about everything imaginable—from interpreting form results to sending email to generating fast, dynamic Web content.


5.1 ASP Basics

ASP is a feature of the Microsoft Internet Information Server. Because the server-side script is simply building a regular HTML page, however, ASP can be delivered to any browser. The parts of the code that are to be executed on the server are enclosed within <% and %> tags. These symbols are referred to as the delimiters for ASP.

TIP: When a delimiter tag is left off, you will get the following error:

    Active Server Pages error `ASP 0116`
    Missing close of script delimiter
    /bad_script_tags.asp, line 8
    The Script block lacks the close of script tag (%>).

The above error is usually caused by not closing your scripting tag. Many editors now color-code your blocks of code and let you know if you forgot to close a tag.

Some recommended HTML editors are Macromedia Dreamweaver, Microsoft FrontPage, and Adobe Go Live, to name a few. However, the best development studio for ASP is Microsoft’s Visual Interdev. Visual Interdev will also let you manage your SQL Server database (All BLUEHILL.com NT Solution accounts include this option).

ASP files must end with a .asp extension in order to be processed by the server. Because ASP files were meant to deliver HTML files, you can include normal HTML tags inside of your ASP files. HTML tags are just sent along to the client’s browser.

Now that we have covered the basics of ASP, we can begin to take a closer look.


5.2 ASP Boot Camp

Example 1 Hello World will introduce our first ASP project. This section is designed to get you more familiar with both ASP and VBScript by covering some of the basic VBScript functions and routines. For a better understanding of any VBScript function, method, property, or constant described here, please see Chapter 29, Visual Basic Scripting Language Reference.

This section covers some very basic examples of VBScript and ASP Objects. There are many more in-depth applications available with ASP that are beyond the scope of this guide.

5.2.1 Delimiters – Distinguishing between Code and HTML

As mentioned in Tip 5-1 ASP Delimiters, the delimiters for ASP start with the <% tag and end with the %> tag. As also mentioned previously, we can include ASP code and HTML within a single document.

To illustrate the integration of HTML and ASP tags, the following example writes some text in HTML, and displays the final output in ASP.

Please view the ASP example, which is located at http://www.4domains.com/ntguide/hello_world.asp . This example was created with the following code:

Example 1 Hello World
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<Title>BLUEHILL.com Hello World! ASP Example</title>
</HEAD>
<BODY background="" bgColor=#ffffff>
<P>From all of BLUEHILL.coms Staff we would like to say,</P>
<h2>
<%
Response.Write "Welcome to BLUEHILL.com NT Solutions!"
%>
</h2>
</BODY>
</HTML>

As you can see, the above example contains both HTML tags and ASP Tags. The server starts to process our page. The server actually does not do anything different until it sees the first <%. We can choose to put our ASP tags anywhere we choose in the page.

We are allowed to put ASP tags when we are trying to write HTML as well. We can modify the above example to read:

Example 2 ASP Inline Tags
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<Title>BLUEHILL.com Hello World! ASP Example</title>
</HEAD>
<BODY background="" bgColor=#ffffff>
<P>From all of BLUEHILL.coms Staff we would like to say,</P>
<h2>
Welcome to <%="BLUEHILL.com NT Solutions!"%>
</h2>
</BODY>

</HTML>

The above example produces the same output as the previous one. We could have also chosen to write out the entire example using ASP. Our code to do this would look like:

Example 3 Hello World (All ASP)
<%
Response.write "<HTML>" & vbcrlf & _
"<HEAD>" & vbcrlf & _
"<META NAME=""GENERATOR"" "& vbcrlf & _
"Content=""Microsoft Visual Studio 6.0"">" & vbcrlf & _
"<Title>BLUEHILL.com Hello World! ASP Example</title>" & vbcrlf & _
"</HEAD>"& vbcrlf & _
"<BODY bgColor=#ffffff>"& vbcrlf & _
"<P>From all of BLUEHILL.coms Staff we would like to say,</P>"& vbcrlf &_
"<h2>" & vbcrlf & _
"Welcome to BLUEHILL.com NT Solutions!" & vbcrlf & _
"</h2>" & vbcrlf & _
"</BODY>" & vbcrlf & _
"</HTML>"
%>

The output of the above code can be seen at the following URL:

This example would produce the same output as the previous two examples. However, in this example notice that we have doubled some quotes. In VBScript we need to double quotation marks that we want to output. Because VBScript uses quotation marks as delimiters for strings, it allows us to output that delimiter by putting two of them together inside the string. If we needed to output two quotation marks, the source would look like:

    Response.write """"

This code snip would give us our desired output.

In Example 3 Hello World (All ASP), we used the & symbol to combine the set of strings into one large one. We let the ASP processor know that we were continuing the string on the next line by using the _ symbol. With this symbol, we see another delimiter of ASP. The ASP processor listens for the <% and %> characters. However, VBScript looks for the new line character to let it know that we are moving onto the next command inside of our code. If we wish to assign a value to a variable and output the result, we would have to execute the following code:

    Dim A
    A=5
    Response.write A

We see that each action that we want to do goes on a different line. The first line declares our variable. The second assigns the variable a value. The last line writes the value of the variable out. If we would have written the code above in the following order:

    Dim A A=5 Response.write A

We would get the following error:

    Microsoft VBScript compilation error `800a0401`
    Expected end of statement

    bad_line_delimiter.asp, line 2

    Dim A A=5 Response.Write A
    ------^

The output of the above code can be viewed at the following URL:

We can see how important it is to have the proper delimiter in code.

We can let VBScript know that we are placing another command on the same line by separating them with a colon. We can see this in the following example:


    <%
    Dim A:A=5
    Response.write A
    %>

The output of the above code can be viewed at the following URL:

Now that we see the importance of having the correct delimiter inside our code, there is still one question left to answer: Why did we have the VBScript constant vbCrLf? The answer is that vbCrLf formats the output of the script to appear identical to that of the other two examples. If we look at the HTML source of Example 3 Hello World (All ASP), we see that it is identical to Example 1 Hello World. Now that we have covered a simple output script, we are now going to look at a simple example that will get data from an HTML form.


5.2.2 Getting HTML Form Data

HTML forms are the way that we can get the user to give us data. This data may be their username and password, it may be a product request, or it may even be an order. ASP allows us to use the request object to get data from the user. If we consider a simple example of a form that asks the user to input their name:

Example 4 Name Demo HTML

    <html>
    <head>
    <title>BLUEHILL.com ASP Name Demo</title>
    </head>
    <body bgcolor="#FFFFFF">
    <p>Welcome to the Name Demo</p>
    <form method="post" action="name_demo_asp.asp">
    <input type="text" name="inputname">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>

The above page displays an input box for the user to type their name in. We can then make the resulting page display the information that they submitted on the previous page. To do this, we need to create the following:

Example 5 Name Demo ASP Source

    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <title>Name Demo Results</title>
    </HEAD>
    <BODY bgcolor=#ffffff>
    <h1>Welcome
    <%
    Response.Write request("inputname")
    %> !</h1>
    <p>Click <A href="name_demo.html">here</a> to try again.</p>
    </BODY>
    </HTML>

The output of the above code can be viewed at the following URL:

We start this example of with HTML for most of the script. The important line is

    Response.Write request("inputname")

In this line, we see that we are writing data out to the page, as we did in Example 2 ASP Inline Tags. However, instead of writing out a simple string, we return the data entered in the form. The request object lets us get data from an HTML form that is submitted. We only need to include in quotes the name of the form element that we are trying to get. If we look at Example 4 Name Demo HTML, we see that the text form element’s name is identical to the one that is in the request.

Tip 5-2

When a HTML field name is included twice in the same html form:

    <html>
    <head>
    <title>BLUEHILL.com ASP Name Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF">
    <p>Welcome to the Name Demo</p>
    <form method="post" action="name_demo_asp.asp" id=form1 name=form1>
    <input type="text" name="inputname"><br>
    <input type="text" name="inputname">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>

    Example 5 generates the following output: Welcome aaaa, !
    Click here to try again.

Notice how the request variable treated the same name input variables as one variable, but separated them with a comma. This could give our code unpredictable results.

For more information on ASP, please refer to Chapter 32, Additional Resources: ASP



Previous Section
Table of Contents
Next Section


Why Us? | About | Contact Us
Knowledge Base | Support
Expired Domains | Domain Name Auctions | VPS Directory | DNS Tools
Hosting Terms | Domain Terms | Privacy Policy
Copyright © 2009 - 4Domains.com, Inc.


web hostinghostingdomaindomain namedomain namescheap web hostingecommerce website designdomain registration

Web Monitoring | SEO Technology | Hacker Scanner | DNS Tools | Online Backup