Active Server Pages with FrontPage 98

Previously, I have talked about the use of IDC (Internet Database Connector) to access databases with FrontPage. Well, Microsoft has recently released FrontPage 98, and although you can still work on IDC "chains" with it, IDC is not directly supported. Instead, Microsoft wants to encourage everyone to use ASP (Active Server Pages) instead, and is gradually phasing out support for IDC. If you have IDC pages in your webs, don't worry, though. IIS (Internet Information Server) will continue to support IDC. You may just find it more difficult to work on your IDC pages with FrontPage 98.

Why is Microsoft phasing out IDC? It's a long story. Actually, Microsoft has developed a number of technologies for remote database connectivity, for use with various programs. IDC, AOD, and RDO are a few. They are hoping to phase all of these out in favor of ADO (ActiveX Data Objects). There are any number of good reasons for consolidating all of these into a single technology, as I'm sure you can guess. ASP supports ADO, through its' use of server-side scripting, and ADO has a number of characteristics which make it a much better technology than IDC. With ADO, you can work directly with your cursors, manipulate your data invisibly, and even run multiple queries from a single page. In fact, you can do virtually anthing with ADO that you can do through a conventional database front-end. That's the basics in a nutshell.

What exactly is ASP? Active Server Pages are web pages with special tags, containg scripting (usually VBScript, although Javascript is also available) which is run on the server, and never even seen by the browser. This is called "server-side scripting." There are any number of reasons why this is a good idea: No longer do you have to worry about the browsers' capability of interpreting scripting correctly; the pages are therefore compatible on any browser. Your code is hidden, and safe from prying eyes, and those who would steal what you spent so much time writing. And the processor and memory burden is shifted from the browser to the server. While ISPs may not be too thrilled about this, it makes the pages more universally available to people with limited capacity computers. These pages are not seen directly by the browser. Instead, the server reads the pages, runs the server-side scripting, and formats a dynamically generated page to the browser. The possibility for generating dynamic pages is virtually limitless. ASP pages are identified by the file extension ".asp"

FrontPage 98 is eminently suited for creating ASP pages. It's editor can create the HTML portions in the typical WYSIWYG interface, and you can insert ASP tags wherever you want them on the page. The following illustration shows a typical ASP page in the FrontPage editor:

asp1.jpg (18867 bytes)

This is a view of "messages.asp," part of a new discussion area I've developed for my website at http://www.connectrans.com/takempis. You'll notice the conventional Javascript icons at the top, but notice also the VBScript icons in several parts of the page. These are actually ASP tags, which are used to customize the page according to the results of a database query. The first tag contains the code which runs the database query. The second tag writes the name of the discussion area after the words "Welcome to." The third tag contains more database operations, which perepare the data to be displayed in the lower part of the page.

To create an ASP tag, all you have to do is position the cursor where you want the tag to go and select Insert|Advanced|Script... from the menu, or click the Script icon in the Advanced Toolbar. The FrontPage 98 script dialog has an additional checkbox which you can check to make the tag an ASP tag, as illustrated below:

asp2.jpg (18984 bytes)

This is the dialog box for the second ASP tag on the page, which writes the discussion group name after the words "Wecome to." When you check the box with the label "Run Script on Server, an ASP tag is created, rather than a conventional scripting tag. The asp tags look (in HTML) like the following: <%Response.Write groupid%> When the server encounters one of these tags, it runs the script, and does whatever the script says it should. In this case, it writes the value of the variable "groupid" to the page in the position where the script occurs.

Here's the complete text of the first scripting tag, which performs the initial database operation:

'** Create recordset object

Set rs = Server.CreateObject("ADODB.Recordset")

'** if this came from clicking a hyperlink on home page, get subject listings

if Request.Form("adminrecno") = "" then
    adminrecno = Request.QueryString("adminrecno")
    q = "SELECT Max(recno) AS rec, Min(group) AS groupid," &_
        "Max(adminrecno) AS adminrec, Min(subject) AS sub," &_
        "COUNT(subject) AS num, MAX(date) AS latest " &_
        "FROM messages WHERE adminrecno=" &_
        adminrecno & " GROUP BY subject ORDER BY Max(messages.DATE), Max(recno)"
    rs.Open q, "DSN=employment;"
    groupid = rs("groupid").value
    adminrecno = Cstr(rs("adminrec").value)

'** if a form was submitted, insert new record, then pull subjects info from messages

else
    adminrecno = Session("adminrecno")
    username = Request.Form("username")
    email = Request.Form("email")
    subject = Request.Form("subject")
    message = Request.Form("message")
    groupid = Session("groupid")
    q = "INSERT INTO messages ([date],[group],[name],[email],[message]," &_
        "[subject],[adminrecno]) VALUES (Date(),'" & groupid & "','" &_
        username & "','" & email & "','" & message & "','" & subject & "'," &_
        adminrecno & ")"
    rs.Open q, "DSN=employment;"
    q = "SELECT Max(recno) AS rec, Min(group) AS groupid," &_
        "Max(adminrecno) AS adminrec, Min(subject) AS sub," &_
        "COUNT(subject) AS num, MAX(date) AS latest " &_
        "FROM messages WHERE adminrecno=" &_
        adminrecno & " GROUP BY subject ORDER BY Max(messages.DATE), Max(recno)"
    rs.Open q, "DSN=employment;"
end if
Session("adminrecno") = adminrecno
Session("groupid") = groupid

Note the use of various objects in this script. for example, you may note the line of code which reads: Set rs = Server.CreateObject("ADODB.Recordset") This is referencing the ADO object model. Some of the other object references are directly from the ASP object model. Without going into too much detail, ASP has several built-in objects which perform most of the work. The most important of these are:

There are a number of others, and as you've seen, you can create objects, such as ADO objects, as well, and work with them. But I've probably "pushed the envelope" by going into this much detail in an article intended to give you an "introduction" to ASP with FrontPage 98.

FrontPage 98, as you can see, can make creating ASP page remarkably easy (all things considered!). If you're not a programmer, find a good book on VBScript. It's not that difficult a language to learn, and there are plenty of samples of VBScript and ASP code available from Microsoft. In fact, FrontPage 98 comes with a few. It also has the Database Region Wizard, which can write a lot of the code for you.

ASP is the coming thing, friends. Why not take a look at it?

Author: Kevin Spencer
Date: 11/14/97

More articles about Microsoft FrontPage
More articles by Kevin Spencer
Author Biography

body>