ASP (Active Server Pages)

ASP is not really a language in itself, it's an acronym for Active Server Pages, the actual language used to program ASP with is Visual Basic Script or JScript. The biggest drawback of ASP is that it's a proprietary system that is natively used only on Microsoft Internet Information Server (IIS).

What are some of the ASP? Most people believe that is much faster to create fully functional service side scripts in ASP then say CGI. You are able to connect to a database with just a few lines of code or mix and match ASP and HTML. Another big advantage is the flexibility of how you write the code. Most people use VB SCRIPT or JSCRIPT.

Since ASP will allow you to choose the syntax you develop with you will to define this to allow the interpreter to know what language you are using.
At the top (first line) of you ASP page you show add:

<@ LANGUAGE="VBSCRIPT" %>
or
<@ LANGUAGE="JSCRIPT" %>

Script is specifically looking for code that is place in between <% and %>. Any text in between these designators will be parse by this inside as code. You are able to mix and match this code.

Example (example1.asp):

<@ LANGUAGE="VBSCRIPT" %> 
<HTML>
<TITLE>My First ASP!</TITLE>
<BODY>
<CENTER>My First ASP!
<BR>
<% Response.Write("I am well on my way to learning ASP!") %>
<BR>
All done!</CENTER>
</BODY>
</HTML>

the ASP code starts (note the "<%"). Here an object was inserted. The Response.Write object allows text (or HTML code) to be passed back from the server to the client.

ASP and databases

Here is the code that you can use to gather info and insert it into your database:

File: new.asp

<html>
<head>
<title>Create Entry</title>
</head>
<body BGCOLOR="#FFFFFF">
' This include is used for ADO access w/VB Script
<!--#include file="adovbs.inc"-->
<%
'Check to see if this is the first time 
 the page has been loaded.
'If there is data to be processed, 
 this section will execute.
If Request.ServerVariables("Content_Length")>0 Then
 If "Insert" = Request("ActionType") Then
  'Create a connection to the database.
   Set DataConn = Server.CreateObject("ADODB.Connection")
   Set RS = Server.CreateObject("ADODB.RecordSet")
   DataConn.Open "DBQ=" & Server.Mappath("cdemo.mdb") & ";
   Driver={Microsoft Access Driver (*.mdb)};"

  'Open the record table and then insert the record.  
     RS.Open "tblContact", DataConn, adOpenKeyset, 
	 adLockOptimistic 
     RS.AddNew
     
     RS("Name") = Request("Name")
     RS("Email") = Request("Email")
     RS("Phone") = Request("Phone")
     RS.Update
    
     'Cleanup - Close database connection.
     RS.Close
     DataConn.Close
     
    'Send text to the user to know they have completed the 
    'process with no errors. 
	   Sever will display errors fatal errors.
   Response.Write "<CENTER>Thank you!</CENTER>"
  Else
%>
' Show the user what they are about to save.
<pre>
  Name:  <b><%=Request("Name")%></b>
  Email: <b><%=Request("Email")%></b>
  Phone: <b><%=Request("Phone")%></b>
</pre>

<p><br>
Do you want to submit this report as shown
          (Hit "back" on your browser to edit)?
</p>

<form METHOD="POST" 
ACTION="<%=Request.ServerVariables("SCRIPT_NAME")%>">
  <input type="hidden" name="Name" 
  value="<%=Request("Name")%>">
  <input type="hidden"  name="Email" 
  value="<%=Request("Email")%>">
  <input type="hidden" name="Phone"  
  value="<%=Request("Phone")%>">
  <input type="hidden" name="ActionType" 
  value="Insert"> <p>
   <input TYPE="SUBMIT" VALUE="Yes!"> </p>
</form>
<%  
  End If
Else
%>
'Input new record information. 
<form ACTION="<%=Request.ServerVariables("SCRIPT_NAME")%>"
     METHOD="POST">
  <div align="left"> 
  <p>Welcome. Please fill in all fields. <br>
  </p>
  </div> <blockquote>
    <div align="center">
	<div align="center"> <center>
	<table border="0" width="512" height="78"
	               cellspacing="0" cellpadding="0">
      <tr>
        <td width="500" height="22" colspan="2">
		Enter Information. <br> </td>
      </tr>
      <tr>
        <td width="171" height="7">Name </td>
        <td width="329" height="7"> 
		<input type="text" name="Name" size="35">
		 </td>
      </tr>
      <tr>
        <td width="171" height="7">Email </td>
        <td width="329" height="7"> 
		<input type="text" name="Email" size="35">
		 </td>
      </tr>
      <tr>
        <td width="171" height="7">Phone </td>
        <td width="329" height="7"> 
		<input type="text" name="Phone" cols="35">
		 </td>
      </tr>
    </table>
     </center> </div> <div align="center">
	  <center> <table>
       <tr>
         <td> <div align="center"> 
		 <center> <p>
		  <input TYPE="SUBMIT" VALUE="Preview">
		   </td>
       </tr>
     </table>
     </center> </div> </div>
   </blockquote>
 </form>
 <% End If %>
 </body>
 </html>








 
 Privacy Statement | Disclaimer | Copyrights © 2004, Wingck'C Web Technologies. All Rights Reserved open source of GNU