Microsoft KB Archive/158737

{|
 * width="100%"|

-

The information in this article applies to:


 * Active Server Pages

-

SUMMARY
This article provides information on how to create a simple query form using Active Server Pages and ActiveX Layout (ALX) files. This example displays a record from a database in the ALX, and then allows the user to query for a different record, which appears in the same form.

MORE INFORMATION
Below are two sections of code: a main page (Page1.asp) and the ActiveX Layout file (Query.asp.) Save these files to the same directory with the file names as given. Make sure that the directory and the files are saved and has Execute and Read permissions from the Internet Information Server (IIS) Manager.

Main Page: Page1.asp
  <% Response.Expires = 0 %> Title

<%  If Not IsObject(Session("cn")) Then REM Create connection object if necessary Set cn = Server.CreateObject("ADODB.Connection") cn.Open "AdvWorks"

REM Gather initial data Set rs = cn.Execute("SELECT * FROM CUSTOMERS WHERE CustomerID=1") Set Session("cn") = cn

REM Place the information to be displayed in the ALX in session REM variables, because the ALX will be parsed AFTER this page loads. Session("ID") = rs(0) Session("Name") = rs(1) Else On Error Resume Next

REM Restore existing connection Set cn = Session("cn")

REM Query is based on ID submitted in form MySQL = "SELECT * FROM CUSTOMERS WHERE CustomerID=" &   Request.Form("ID") Set rs = cn.Execute(MySQL) If Err = 0 Then Session("ID") = rs(0) Session("Name") = rs(1) Else REM Query Failed Session("ID") = "None Found" Session("Name") = "None Found" End If  End If   %>    

Layout File: Query.asp
   

        <PARAM NAME="VariousPropertyBits" VALUE="746604571"> <PARAM NAME="Size" VALUE="3493;564"> <PARAM NAME="Value" VALUE="<%=Session("ID")%>"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> </OBJECT>  <PARAM NAME="Caption" VALUE="Get Item"> <PARAM NAME="Size" VALUE="3493;882"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="3"> </OBJECT>  <PARAM NAME="Caption" VALUE="Company Name"> <PARAM NAME="Size" VALUE="3493;600"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> </OBJECT>  <PARAM NAME="VariousPropertyBits" VALUE="746604571"> <PARAM NAME="Size" VALUE="3493;564"> <PARAM NAME="Value" VALUE="<%=Session("Name")%>"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> </OBJECT> </DIV> When Page1.asp is requested from a browser. the following sequence of events occurs.
 * 1) Browser requests Page1.asp from IIS.
 * 2) IIS receives the request and recognizes the page as a script page.
 * 3) IIS processes the script page.
 * 4) In processing the script, a connection is stored as a session variable.
 * 5) An initial query is performed, and two more session variables holding the CustomerID and the CustomerName are created.
 * 6) IIS passes the resulting HTML code from Page1.asp back to the browser.
 * 7) The browser begins displaying the page until it reaches the OBJECT tag that points to Query.asp.
 * 8) The browser requests Query.asp from IIS.
 * 9) IIS parses the Query.asp script tags and places the Name and ID into the text boxes in the layout.
 * 10) IIS passes the Query.asp back to the browser, which interprets the file as a layout file (ALX).
 * 11) The ALX appears, and the browser now waits for user input.
 * 12) The user can input an ID into the first text box, and click Command to perform the search.
 * 13) The Command button calls VBScript, which calls a procedure in Page1.asp.
 * 14) The procedure in Page1.asp populates a hidden form and then submits the form to itself (Page1.asp).
 * 15) Page1.asp is run as a script again.
 * 16) Page1.asp recognizes that it has been called by a form and constructs a SQL query based on information passed.
 * 17) It then populates the session variables ID and Name.
 * 18) The page is passed back to the browser, which displays it, and again requests the Query.asp layout page.
 * 19) Query.asp is parsed as a script and returns a valid ALX layout file.
 * 20) The results appear on the screen.

NOTE: This example requires the AdvWorks data source set up during the Active Server Pages installation.