Share via


Visual Basic Concepts

Key Events in DHTML Applications

Your DHTML application goes through several main events during its lifetime. There are three objects involved in the life of the application:

  • The BaseWindow object represents an instance of the browser and is used to display the Document object.

  • The Document object represents the HTML page the end user views in the Web browser or Web browser control. You use events in the Document object to access the object model and handle user actions in the browser. The Document object, in turn, contains the DHTMLPage object.

  • The DHTMLPage object is contained by the document object, and represents a run-time utility that hooks up the page to its Visual Basic code when the application runs. The DHTMLPage object provides functionality such as a load, unload, initialize, and terminate events for your HTML pages. You cannot access the DHTMLPage object directly through the Document object.

The following figure shows how these objects work together:

Page Designer Top-Level Objects

The DHTMLPage object manages the lifetime of your HTML pages with the following sequence of events:

  1. The Initialize event occurs early in the loading process, whenever the run-time DLL for the application is created or recreated by the system. It is always the first event in a DHTML application. When the Initialize event is fired, not all objects on the page have been loaded, so object references may not be valid. Because of this, you should not use the Initialize event to reference and set properties for elements on the page.

  2. The Load event occurs later in the loading process, after the Initialize event. If your page is loading , the Load event is fired after the first element on the page has been created. If your page is loading synchronously, the Load event is fired after all of the elements have been created. You can use the Load event to set information on the page.

  3. The Unload event occurs when the end user moves to another page referenced by the DHTMLPageDesigner object or closes the application. During unload, all of the objects on the HTML page still exist. This is therefore a good time to do any state management, cleanup, or other processing that needs to reference items on the page.

  4. The Terminate event occurs when the HTML page is about to be destroyed. None of the objects on the page exist in memory during the terminate event, so you cannot use this event to reference items on the page for state management or other processing.

For More Information   See "Document Object Model" in the "Dynamic HTML" section of the Internet/Intranet/Extranet Services SDK for a full list of the properties, methods, and events available for the Document object. For information on how to use the Dynamic HTML object model in Visual Basic, see "Writing Code with Dynamic HTML" in this chapter.