Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems


ASP Server Object CreateObject Method

The CreateObject method creates an instance of a server component. If the component has implemented the OnStartPage and OnEndPage methods, the OnStartPage method is called at this time.

Syntax: ASP Server Object CreateObject Method

Obj = Server.CreateObject( progID )

Parameters: ASP Server Object CreateObject Method


A variable name for the object


Specifies the type of object to create. The format for progID is [vendor.]component[.version].

Remarks: ASP Server Object CreateObject Method

By default, objects created by the Server.CreateObject method have page scope. This means that they are automatically destroyed by the server when it finishes processing the current ASP page.

To create an object with session or application scope, you can either use the <OBJECT> tag and set the SCOPE parameter to SESSION or APPLICATION, or store the object in a session or application variable.

Examples: ASP Server Object CreateObject Method

You can destroy an object by setting the variable to NOTHING or setting the variable to a new value, as shown below. The first example releases the object ad. The second replaces ad with a string:

<% Session("ad") = Nothing %>

<% Session("ad") = "some other value" %>

You cannot create an object with the same name as a built-in object. The following example will cause an error:

<% Set Response = Server.CreateObject("Response") %>

The following example creates an instance of the MSWC.BrowserType component. This component can be used to determine the capabilities of the browser requesting the page.

<% Set MyB = Server.CreateObject("MSWC.BrowserType") %>

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.