Sunit Katkar's Home Page

 Tutorials:



 ASP COM Links:
 

Steps for building our component: 2

Step 7: On the ASP tab let the default selections be as they are.
The checked items under Intrinsic Objects tell you that you will get a refrence to all the built-in ASP objects.
Let the OnStartPage/OnEndPage methods be checked.

Let ASP tab have default selections
Figure 7 - Let the ASP tab have default selections

Note: We are not building a Microsoft Transaction Server® (MTS) aware component nor a Application level component. We are building a page level component, which means that it will be instantiated when a ASP page starts executing and will be destroyed when it finishes executing. Hence, we require the OnStartPage/OnEndPage methods.

Whenever a ASP page starts executing and calls a COM component, the OnStartPage method inside the component is called. When the ASP page finishes executing the OnEndPage method is called. Any resources allocated in the OnStartPage method should be released in the OnEndPage method. Typically the pointers to the built-in ASP objects are retrieved in the OnStartPage and are released in the OnEndPage.

Examine the code that the ATL Object Wizard has added. You will see that the code for acquiring and releasing the built-in (or intrinsic) ASP objects in these methods has been already added for you. (In our example, see the file ProcessForm.cpp which is part of the download.)

Explore the Class View in the Workspace window
Figure 7a - Explore the Class View

From the Workspace Window select the Class View tab. Expand  each node and see the new classes and interfaces that have been added by the ATL Object Wizard.

From the Workspace window look at ProcessForm.cpp in File View or click on OnStartPage(...) in Class View. The work of getting pointers to the intrinsic ASP objects is already done for us by the wizard.

Look at the method:

STDMETHODIMP CProcessForm::OnStartPage (IUnknown* pUnk)

Had this been a MTS aware component we would get the ObjectContext instead of the Scripting Context to access the intrinsic ASP objects. There would be some other changes to the code too. But more about it in later tutorials.

Now we will implement two mehods for processing FORM submissions. One method called FormGET(...) for HTML forms posted with GET method and the other called FormPOST(...) for forms posted with POST method.

Step 8: In Class View right click on the IProcessForm interface and select Add Method.

Add a new FormPOST method
Figure 8 - Adding a new method to the Inetrface

 

Step 9: Enter FormPOSTin the Method Name field.
This method will process the Form collection to give the fields and values of the submitted form.
Values are being passed neither in nor out, so there will be no parameters to this method.
The ASP Request and Response objects will be used to get the values from the Form collection and write them back to the ASP page.

Add a method - FormPOST
Figure 9 - Add a FormPOST method here. You can click on Attributes and add a more descriptive help string.

 

Step 10: Similar to Step 9 above add another method FormGET to process Querystrings.

Main |  1 |  2 |  3 |  4 |  5