Microsoft KB Archive/172926

= INFO: Breakdown of Data Form Wizard Code =

Article ID: 172926

Article Last Modified on 5/2/2006

-

APPLIES TO


 * Microsoft Visual InterDev 1.0 Standard Edition

-



This article was previously published under Q172926



SUMMARY
Microsoft Visual InterDev provides a Data Form Wizard to generate sample Active Server Pages (ASP) for simple data management. This article breaks down how these pages function so that users may better understand them if they wish to make changes to add functionality.

NOTE: Microsoft Technical Support does not directly support any changes made to the code that is the Data Form Wizard produces. Changes rendered are considered to change the code from "Wizard" code to "User" code and are supported as if they were a user-written application.



MORE INFORMATION
When completed, the Data Form Wizard produces three files. These files are named according to the following conventions:   xxxxForm.asp xxxxList.asp xxxxAction.asp where xxxx represents the name that is given when you click New on the File menu to select the Data Form Wizard.

All of these files follow a similar format. Each file contains a set of initial  tags that contain the various functions and procedures that the page calls. Following this section is the body of the document. This is the HTML code and ASP code that is then processed sequentially.

xxxxFORM.ASP And xxxxLIST.ASP
In xxxxForm.asp and xxxxList.asp (hereafter referred to as Form.asp and List.asp), the body of the document contains four main sections:


 * Heading Section
 * Data Range Header
 * Field display code
 * Data Range Footer

Heading Section
The heading section is responsible for displaying the various actions that are valid for the form. This code checks for what state the form is in and displays the appropriate buttons. The state of the form can vary between edit mode, filter mode, and display. Each button displayed is a submit button that calls the xxxxAction.asp.

Data Range Header
The Data Range Header (DRH) is simply code that the Data Range Header Design-Time Control (DTC) produces. This section of code is delimited by the following tags: To change any of this code, you can right-click within this area, and then click Edit Design-time Control. Note that you can change the fields that are included in the form here, but doing so is not sufficient to affect changes in the rest of the form; this must be done manually. More information on this will come later.

Note the following key settings on this Design-Time Control:
 * Record Paging is Enabled
 * Record Paging Size is 1 for Form.asp and 10 for List.asp
 * Range Type is Form for Form.asp and Table for List.asp
 * Both List.asp and Form.asp require that the CursorType NOT be ForwardOnly for paging to function properly

Data Range Footer
The Data Range Footer (DRF) is similar to the Data Range Header. Towards the bottom of both of these documents, you can find similar sections that are delimited by another set of the same tags. Be careful not to mistake the endspan tag of the DRF as the endspan of the DRH. This control is responsible for ending the data section and displaying the navigation buttons, which are all submit buttons that call xxxxAction.asp. When ending the data range when the Data Range Header has a Paging Size greater than 1, it causes the form to loop back and process any information that is contained between the DRH and DRF. This is what allows the List.asp to display 10 records at a time.

Field Display Code
This section of the document appears between the DRH and the DRF. It contains all the information that is displayed on each pass through the loop that is established by the DRH and DRF. In the case of the Form.asp, this happens only once, and consequently only one record is displayed.

In both List.asp and Form.asp, this code is simply a set of calls to a function that is defined at the beginning of the page: ShowField. This function accepts four parameters, which define the name of the field, the description text, whether or not the field is an Identity/Autonumber field, and finally an optional array if you want to display the field as a drop-down list box. In the ShowField function, these parameters are defined as follows:   strFieldName, strLabel, blnIdentity, avarLookup strFieldName: The fields to be displayed by calling ShowField must be part of the Recordset that the DRH fetches. This field is passed as a string and is the exact name of the column in the Recordset.

strLabel: This is a text string representing the text that will be displayed as a column heading in List.asp and next to the text box in Form.asp.

blnIdentity: This is a Boolean (true/false) value indicating whether or not the field is an autonumber or identity field. These are automatically calculated and consequently not editable.

avarLookup: This is not accessible through the Data Form Wizard interface and must be adjusted in the form itself. ShowField looks for a two-dimensional array to be passed in this variable. The first column of data in the array should be an index, while the second column contains the data to be displayed instead of this index when editing. The form displays a drop-down list box in place of the field so that a user may select from the values in the second column of the array that is passed to ShowField.

The ShowField function examines the field that is passed to it and determines how it should display it. How the field is displayed depends on what data type it is and whether the form is in edit mode or not.

xxxxAction.asp
This file is responsible for processing all button presses from either the List.asp or Form.asp. It to begins with various functions that are defined in the  tags. The body of this page performs one of two basic actions: either it processes the command and then loads one of the other two forms, or it displays information. The information displayed is either a confirmation of an action you performed or information about an error that has occurred.

In the Action Handler section of this page, the VBScript code checks to see which button was used to call the page and acts accordingly.

