HOWTO: How To Create a Simple Query in an ActiveX Layout
ID: Q158737
|
The information in this article applies to:
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 %>
<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.
- Browser requests Page1.asp from IIS.
- IIS receives the request and recognizes the page as a script page.
- IIS processes the script page.
- In processing the script, a connection is stored as a session variable.
- An initial query is performed, and two more session variables holding
the CustomerID and the CustomerName are created.
- IIS passes the resulting HTML code from Page1.asp back to the browser.
- The browser begins displaying the page until it reaches the OBJECT tag that points to Query.asp.
- The browser requests Query.asp from IIS.
- IIS parses the Query.asp script tags and places the Name and ID into the text boxes in the layout.
- IIS passes the Query.asp back to the browser, which interprets the file as a layout file (ALX).
- The ALX appears, and the browser now waits for user input.
- The user can input an ID into the first text box, and click
Command to perform the search.
- The Command button calls VBScript, which calls a procedure in
Page1.asp.
- The procedure in Page1.asp populates a hidden form and then submits the form to itself (Page1.asp).
- Page1.asp is run as a script again.
- Page1.asp recognizes that it has been called by a form and constructs a SQL query based on information passed.
- It then populates the session variables ID and Name.
- The page is passed back to the browser, which displays it, and again
requests the Query.asp layout page.
- Query.asp is parsed as a script and returns a valid ALX layout file.
- The results appear on the screen.
NOTE: This example requires the AdvWorks data source set up during the Active Server Pages installation.
REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q157748
Modifying Objects in an ActiveX Layout
For the latest Knowledge Base articles and other support information on
Visual InterDev and Active Server Pages, see the following page on the
Microsoft Technical Support site:
http://support.microsoft.com/support/vinterdev/
Additional query words:
1.00 kbdsi
Keywords : kbActiveX kbADO kbASP kbASPObj kbScript kbGrpASP
Version : winnt:
Platform : winnt
Issue type : kbhowto