Page-level Event Methods

In IIS 3.0, objects accessed the built-in objects by creating an instance of the ScriptingContext object in a page-level event method. This approach is supported in order to be compatible with existing ASP applications. This method of accessing the built-in objects is not recommended. Any new components that you develop should use ObjectContext to access the built-in objects. It is recommended that you modify any components that rely on ScripingContext to use ObjectContext instead.

You can implement two page-level event methods, OnStartPage and OnEndPage, in your component. These methods are optional. ASP pages will work with any Automation object, regardless of whether these methods are implemented.

When the server creates an object instance, it looks for OnStartPage and OnEndPage methods associated with that object's IDispatch interface. If the object has implemented these methods, the server will automatically call the OnStartPage method during script processing before the object is used and call the OnEndPage method when all scripts on the ASP page have been processed.

The only exceptions are objects created with application scope, which never receive OnStartPage or OnEndPage method calls. As the component design guidelines indicate, very few objects should be given application scope. For more information about application-scope objects, see the Global.asa Reference.

Because objects that have been given application scope do not receive a call to the OnStartPage method, they cannot depend on its functionality.

It is recommended that your object, regardless of scope, handle the situation in which the OnStartPage method fails or is not called. A common example of the latter is occurs when the object is created in a way other than the Server.CreateObject method provided by ASP.