Build Logo Rapid Application Development

The Build Team - Specializing in "Proof of Concept" applications
Alliance Logo
Home
   RAD Main
   template.asp
   The addForm Sub
   The Before index.asp
   The After index.asp Page    The After Include Page    Demo

Separating navigation from content when developing applications.
This technique uses form values and query strings to call subs. These subs are placed in an included page. This is the primary technique I use when developing web applications. It is very similar to using includes or server.execute as demonstrated in One Page Web Sites. In fact you can mix the two techniques on the same page. See TechEd Long Beach, for example.

Let's build a simple Message Board application.
First we start with a basic template page:

In this application we'll let messages be added and then display the ten most recent. We start by adding the two navigation links. My convention is to call the query strings "do". Later you'll see where the form values are called "action", it helps keep things organized.

    <a href=<%= Request.ServerVariables("SCRIPT_NAME") %>?do = show>Show </a> |
    <a href=<%= Request.ServerVariables("SCRIPT_NAME") %>?do =add> Add</a>

OK, now  we need a database for this application.  For our purposes of this application we'll only need three fields:
   PostID - autonumber
   PostText - memo
   PostWhen - date/time

In order to restrict the postings to the most recent ten, we'll be using the following SQL statement:
   SELECT PostWhen, PostText FROM postings ORDER BY PostWhen DESC
Then using getrows, we call only ten records
   arrData = objRS.getrows(10)

Now that we have the database, we'll use Buildapp to generate most of the code that we'll be using. We use the "Create HTML Add Form"  link, for example, to generate our add form. Then use "view source" to grab the following code. (While this is a very small form, easily hand coded, when you go to a bigger database you'll appreaciate this feature, which makes form building mostly a copy/paste operation):

<form method=post action="postingsSubmit.asp">
<table>
<tr><td><b>PostText</b></td>
<td><input size=30 name=POSTTEXT></td>
<tr><td>
<b>PostWhen</b></td>
<td
><input size=30 name=POSTWHEN></td>
</tr></table>

<br><input type=SUBMIT name=action value="Add Record"></form>

We now modify it and make it a Sub. Note that POSTWHEN is now hidden with a value of "now()", effectively making it a timestamp and the form will be submitted to this page. The sub, addForm(), is called by clicking on the "Add" link.

Sub addForm()
%>

  <p align=center>
  <form method=post action=
"<%= Request.ServerVariables("SCRIPT_NAME") %>">
  <b>Enter you message:</b><br>
  <textarea rows=
"5" name="POSTTEXT" cols="40"></textarea>
  <input size=
30 type=hidden name=POSTWHEN value=<%= now() %>><br>
  <br><input type=SUBMIT name=action value=
"Add Your Message"></form>
  </p>
<%
End Sub

  ******************************************************

<%
If request("do") = "add" Then
    Call addform()
End If
%>

See this Page

Now we go back to the application generated by Buildapp and grab connect.asp and the submission code and make two more Subs and a Function. Then we add an "Else If" condition to call the new "addPost" Sub.
 We'll call this the index.asp "Before Page". 

Everything seems to be working now, so we'll now make a new include page and move the subs and function there then include the new include.asp page.
We'll call this the index.asp " After Page " and the new include.asp page.

As the subs and functions are built and tested, they are moved to the include page. By doing this the "working space" is uncluttered enabling one to focus on the current step of the application. And if you need to go back and rework an sub or function, simply cut it from include.asp and move back to the index.asp page. When your're finished reworking the code, just reverse the process. The process continues until the application is completed.

    Do Until End of Application
        Build --> Test --> Move
    End Do

The finished message board application disallows duplicate messages and when there are more than thirty records, it automatically deletes 20 messages and compacts the database . When you look at the finished include.asp, note that all the subs and functions are listed at the top of the include.asp page. This is your "Table of Contents" for that page. Do a simple search to quickly locate the particular sub or function that you are looking for.

Do the Demo

For an example of a more complex application that uses this method take a look at the:
   SQL Server Query Analyzer
Other articles:

Michael Brinkley - Janurary 2, 2002
Send comments to: Mbrink1111@yahoo.com