WebRef Update: Featured Article: SOM - Your New Baby | 2 | WebReference

WebRef Update: Featured Article: SOM - Your New Baby | 2

SOM - Your New Baby

First, to use the SOM in an ASP page, you must "turn it on." This is done via a server-side include of the appropriate .JS file from the SOM itself, followed by a function call, as follows:

<!--#include file="_ScriptLibrary/pm.asp"--> <% if StartPageProcessing() Then Response.End() %> <FORM name=thisForm METHOD=post> <HTML> <HEAD>

Also note that the entire HTML document is encapsulated in a form called thisForm defined with a method of POST. Any HTML controls you place on the client page will be a part of this form and their values will be sent to the server whenever the page is submitted. The thisForm is automatically submitted by several of the SOM routines and is integral to its functioning. One trick of using the SOM is learning how to trigger the submission of the form at will while preserving the context and behavior of the SOM, even from other client pages as might happen when using frames. But first, let's finish our look at "turning on" the SOM in an ASP page.

When an ASP page is retrieved from IIS, the Web Application Manager creates an object, known as the Page Object - (now you VI users know where the name for the Page Object DTC control comes from) - and the Page Object in effect represents the particular instance of the execution and processing of the retrieved ASP page. For more information on this, see the excellent article on IIS architecture in MIND magazine at www.microsoft.com/mind/1099/inside/inside1099.htm (a must- read if you do ASP development). You can also find two excellent articles in the MIND archives from 1998 and 1999 which deal exclusively on the SOM. A useful MS KB article lays out the sequence of trappable events when using the SOM. Finally, Mobil Tape (www.mobiletape.com) sells a presentation from the 1999 TechEd on advanced use of the SOM that is well worth the $25 or so.

Back to the SOM, the call made in our example code above results in the creation of the all-important thisPage object, a server- and client-addressable object that represents the current instance of the ASP page. thisPage comes with some extremely useful events, such as OnEnter, which fires at the very beginning of server-side ASP page processing. As a result, any code you place in this event will be the first code executed on the page. Voila! Control over the order of execution! (You can place server code above that block using the Furthermore, thisPage has a property called firstEntered, and you probably just guessed its tremendous value. It tells you whether a client is loading your ASP page for the first time. That means you only have to run start up code once! The list goes on... there's an OnExit event, etc. You get the picture. Your ASP pages are now orders of magnitude more powerful and manageable. It gets better, as you can "reference" one ASP page from another, the same way you reference, say, the ActiveX Data Objects library in a VB project. The routines in the referenced page become available to the referencing page. They in effect define "entry points" in the referenced ASP pages, and can be accessed by the referencing page without leaving it, or can be accessed by navigating to the referenced page and beginning page execution in the called routine!

Let's turn to the client for a moment. Once again, the client page is encapsulated in a giant form called thisForm. The SOM automatically includes a number of hidden fields in thisForm and adds JavaScript code to the page as well to coordinate the activities of client and the server within the context of the SOM. Normally, the client posts back to the server whenever the user clicks on a DTC button and there is a handler for the click event on the server (yes, the event handlers for the DTC controls are on the server in cross-browser pages, and there are other events which cause the client to post as well).

You don't have to wait for the user to click a DTC button to post the form however. You can execute the underlying code yourself. I often use nothing more than a page object and a hidden DTC button object to get all the benefits of the SOM without exposing any of it to my users. That way, I get all the functionality of the SOM, while maintaining complete control from a DHTML point of view. Again, we could go on and on, but the idea here is mainly to provide a level of familiarity with what the SOM has to offer you.

Other valuable benefits of the SOM include the creation and management of page-level properties that can be defined as read- write on both server and client. You could define a page property on the server, initialize it in the "Sub thisPage_OnEnter... If thisPage.firstEntered Then... End If End Sub"-style event handler, modify it on the client, and examine the modified property value in a subsequent round-trip to the server.

As you can see, the SOM delivers a lot. Any serious Web developer would be crazy to ignore this stupendous functionality. Never knew that kid was going to be a Rhodes Scholar, did you? The decision to use DTCs is another issue, as that involves, as I understand it, licensing a copy of Visual Interdev (you can create the DTCs yourself in client code if you want to, and that doesn't require licensing the ActiveX objects themselves). I recommend it, while recognizing you may have settled on an ASP development, data- binding solution of another type and flavor -- GoLive (which uses the SOM, by the way), Cold Fusion, JSP, the new UltraDev, etc. No matter what tool you use, your entire development effort will be enhanced by understanding and using the SOM.

About the author:

Gordon Rose is the lead developer of ActiveCert.com, a site that helps MCSEs upgrade their certifications to Windows 2000. He invites all readers to visit www.activecert.com and take a free practice mini-test. Gordon holds the MCSE, MCSD, MCDBA, MCT, and MCP+I Microsoft certifications. This is Gordon's second article for Webreference.com.

Previous: What is the SOM and Why Should I Care?

This article originally appeared in the July 6, 2000 edition of the WebReference Update Newsletter.


Comments are welcome
Written by Gordon Rose and

Revised: July 7, 2000

URL: https://webreference.com/new/som2.html