The information in this article applies to:
SUMMARYThis 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 INFORMATIONBelow 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 %> <html> <head><title>Title</title></head> <body> <% 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 %> <form name="HiddenForm" action="page1.asp" method="Post"> <input name="ID" type="Hidden" maxlength="5" size="5" value="Nothing"> </form> <script language="VBScript"> <!-- Sub SubmitForm Document.HiddenForm.ID.Value = Window.Html_Layout1.IDTextBox.Value HiddenForm.Submit End Sub --> </script><object classid="CLSID:812AE312-8B8E-11CF-93C8-00AA00C08FDF" id="Html_Layout1" style="LEFT:0;TOP:0"><param name="ALXPATH" ref value="query.asp"></object> </body> </html> Layout File: Query.asp<SCRIPT LANGUAGE="VBScript"> <!-- Sub CommandButton1_Click() Window.Parent.SubmitForm End Sub --> </SCRIPT> <DIV ID="Layout1" STYLE="LAYOUT:FIXED;WIDTH:225pt;HEIGHT:90pt;"> <OBJECT ID="IDLabel" CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0" STYLE="TOP:8pt;LEFT:8pt;WIDTH:99pt;HEIGHT:17pt;ZINDEX:0;"> <PARAM NAME="Caption" VALUE="Customer ID"> <PARAM NAME="Size" VALUE="3493;600"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> </OBJECT> <OBJECT ID="IDTextBox" CLASSID="CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002F3" STYLE="TOP:25pt;LEFT:8pt;WIDTH:99pt;HEIGHT:16pt;TABINDEX:3;ZINDEX:4;"> <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> <OBJECT ID="CommandButton1" CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57" STYLE="TOP:50pt;LEFT:8pt;WIDTH:99pt;HEIGHT:25pt;TABINDEX:2;ZINDEX:2;"> <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> <OBJECT ID="NameLabel" CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0" STYLE="TOP:8pt;LEFT:116pt;WIDTH:99pt;HEIGHT:17pt;ZINDEX:3;"> <PARAM NAME="Caption" VALUE="Company Name"> <PARAM NAME="Size" VALUE="3493;600"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> </OBJECT> <OBJECT ID="NameTextBox" CLASSID="CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002F3" STYLE="TOP:25pt;LEFT:116pt;WIDTH:99pt;HEIGHT:16pt;TABINDEX:1;ZINDEX:1;"> <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.
NOTE: This example requires the AdvWorks data source set up during the Active Server Pages installation.
REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base:
Additional query words: 1.00 kbdsi Keywords : kbActiveX kbADO kbASP kbASPObj kbScript kbGrpASP Version : winnt: Platform : winnt Issue type : kbhowto |
Last Reviewed: May 27, 1999 |