Library tutorials & articles

Using Components and Objects in ASP

Using Objects

To use an object provided by a component, you create an instance of the object and assign the new instance to a variable name. Use the ASP Server.CreateObject method or the HTML <OBJECT> tag to create the object instance. Use your scripting language's variable assignment statement to give your object instance a name. When you create the object instance, you must provide its registered name (PROGID). For the base components provided with ASP, you can get the PROGID for the objects from the reference pages (see Installable Components for ASP). For example, the Ad Rotator component randomly rotates through a series of graphical advertisements. The Ad Rotator component provides one object, called the Ad Rotator object, whose PROGID is "MSWC.AdRotator."

To create an instance of the Ad Rotator object, use one of the following statements:

VBScript:
<% Set MyAds = Server.CreateObject("MSWC.AdRotator") %>

JScript:
<% var MyAds = Server.CreateObject("MSWC.AdRotator") %>

If you are already familiar with VBScript or JScript, note that you do not use the scripting language's function for creating a new object instance (CreateObject in VBScript or New in JScript). You must use the ASP Server.CreateObject method; otherwise, ASP cannot track your use of the object in your scripts.

You can also use the HTML <OBJECT> tag to create an object instance. You must supply the RUNAT attribute with a value of Server, and you must provide the ID attribute set to the variable name you will use in your scripts. You can identify the object by using either its registered name (PROGID) or its registered number (CLSID). The following example uses the registered name (PROGID) to create an instance of the Ad Rotator object:

<OBJECT RUNAT=Server ID=MyAds PROGID="MSWC.AdRotator"></OBJECT>

The following example uses the registered number (CLSID) to create an instance of the Ad Rotator object:

<OBJECT RUNAT=SERVER ID=MyAds
CLASSID="Clsid:1621F7C0-60AC-11CF-9427-444553540000"></OBJECT>

Comments

  1. 22 Feb 2004 at 23:46
    In an interview, they asked me what are the components of ASP and VB. Can any body help me?.
  2. 17 Jul 2002 at 08:02

    If you want to try using components, start using those allready installed on your server. Use this script to check your IIS for installed components:
    http://www.bier-voting.de/objcheck/
     

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Using Components and Objects in ASP.

Leave a comment

Sign in or Join us (it's free).

Talal Ahmed Siddiqui
AddThis

Related podcasts

  • Scott Guthrie

    Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.

We'd love to hear what you think! Submit ideas or give us feedback