Creating your Application
Now that you have created your content and zipped it up nicely into an EzStor/HSP file, you are ready to use it in your application.
Create a VB or .NET project and add the EzTools Library in the Components dialog, as shown here. If using Visual Studio.NET, select the Tools/Customize Toolbox... menu.
Select the WOW control on the toolbar.
Now create a WOW control on your form as shown below. You can set the border color and style to match the motif of your form. Notice that we are mixing VB and other ActiveX controls on the form with the WOW control. These will be used to move through the Customers list. You could easily make the WOW control blend-in with the form by removing the border and setting the background color of the webpage to be the same as that of the form.
Running ASP pages in your Application
We will cause the WOW control to navigate to cust_table.asp, one of our pre-defined ASP pages. We'll do this in the Form's Load event, as shown below:
Private Sub
Form_Load()
wowCusts.Navigate "x-hsp://" & App.Path & "/cust_table.asp"
End Sub
The cust_table.asp ASP file generates the customer listing shown above using a .INI file as its database. Clicking on a customer name loads the customer details page shown below. We could have done this by coding a standard hyperlink with a Querystring in the URL, like this:
<a href="display_cust.asp?custno=<%=strCustNo%>">
However, we would like to take this opportunity to demonstrate how to raise an event in the application's code, so that we can know what action was just taken in the webpage. There are many reasons why you may need to do this, such as opening an "Edit" form to edit the record that was clicked. To cause the WOW control to raise an event, we need to call window.external.RaiseEvent (or RaiseEvent2) using JScript (or JavaScript, or VBScript). In this case, we set the href to "#", as shown below. We set Param1 to "custno" to provide context, and Param2 to the actual Customer number.
<a href="#" onclick="window.external.raiseEvent2('custno', '<%=strCustNo%>')">
When the hyperlink is clicked, the WowCtl.OnRaiseEvent event is fired. We must bind to this event in our application code to make use of it, as shown below:
Private Sub wowCusts_OnRaiseEvent2(ByVal strParam1 As String, ByVal strParam2 As String)
If UCase(strParam1) = "CUSTNO" Then
wowCusts.Navigate "x-hsp://" & App.Path & "/display_cust.asp?custno=" & strParam2
End If
End Sub
This method uses the values of strParam1 and strParam2 to know what happened on the webpage and to take appropriate action - in this case to display the customer record from the database.
Custom External Objects
The WOW control allows you to set your own custom "external" COM object so that you can call any method on your object's interface directly from the webpage using Javascript. The default custom interface that WOW provides has only two methods: RaiseEvent and RaiseEvent2, which you access via the DOM's "window.external" member. You can set your own custom COM object (such as a VB Class or Form object) using the WowCtl.SetExternal method. For example, suppose the main form in your VB app has a function named DoSomething that takes a single string parameter. Here is how you could call it from a webpage. In the VB code for your Form object, add this line:
WowCtl1.SetExternal me
Now in your webpage code you can call functions on the Form directly, like this:
<a href="#" onclick="window.external.DoSomething('the parameter')">Do Something</a>
You can do the same for any HTML element which supports the onClick event. Of course, you don't have to use the element's onClick event - you can use any event, such as onBlur. Its entirely up to you when and how you want to fire events into the application.
Object Injection
There is a way of injecting COM objects into the HSP programming scope, such that you can use them in the VBScript code during the processing of your ASP page. You can do this by using the Server Object in your Application code to "inject" an object into the Server.SessionVar collection, where it can be used by the ASP code. This collection is "static", meaning that it exists for the lifetime of your application. It allows you to provide your own COM object (must be scriptable), either created by you (such as a VB Class or Form object) or an existing COM object (such as an ADO Connection or Recordset).
Here is an example of how to inject an ADO Connection object. Suppose you have a global ADO Connection object in your application, and you want to use it in your ASP pages rather than create a new one each time the pages are run. This code would go in your VB project code:
Dim hspServer as new HSP.Server
'g_dbConn was created in your App's startup code
set hspServer.SessionVar("dbconn") = g_dbConn
Now you can access the Connection object in
the ASP code
<%
Dim cnn
Set cnn = Server("dbconn")
'now you can use it in your ASP code
%>
© Copyright 2003 EzTools Software