Creating Objects on the Client

You'll probably have noticed that no matter whether we're interacting with browser objects on the client, or server-side objects with ASP, that the code we write is very similar. The last chapter showed how we could connect client-side code to objects, how we could respond to events fired by objects, and how we could call methods and access the properties of objects. We also talked about a number of the objects provided by the browser itself. What we haven't covered is how we create instances of additional objects.

On the server, we'd use the <OBJECT> tag with RUNAT=SERVER or the CreateObject method of the Server object, like this:

<OBJECT RUNAT="Server" ID=MyObject ProgID="MyProjectName.MyClassName">
</OBJECT>

or:

MyObject = Server.CreateObject "MyProjectName.MyClassName"

On the client, things work a bit differently, and the objects themselves are quite different from those we've used on the server. However, the great thing is that our code will generally stay the same, in the same way that the syntax doesn't change much when we move from the server to the client. We create objects and hook up code differently, but the code itself is the same—greatly simplifying our task.