Visual Basic Concepts

Template Webitem Events

Tags within an HTML template file can act as event sources if the browser calls the server when the user selects their corresponding HTML elements. Elements call the server if their HTML tags have attributes that contain a URL. For example, when the user selects a hyperlink, the browser sends a URL request to the server to display another page. The hyperlink tag can therefore be treated as an event source in the webclass, because the webclass can intercept this request and process Visual Basic code for it.

When you add a template, Visual Basic scans the file and makes note of each tag within it that can make a server request. The designer displays the attributes of these tags in the right panel. Most tags have only one attribute that can call the server, but some tags, such as the IMG tag, have multiple attributes that can do so. There are three steps to setting up template webitem events:

  1. You choose which of the tag attributes displayed in the Detail panel you want to treat as events.

  2. You perform a process known as "connecting" for each attribute you want to process.

  3. You write code for each connected event.

Connecting an attribute means that you are activating it, or enabling the attribute to be treated as an event. Until an attribute is connected, it does not appear in the Code Editor window for the webclass and you cannot write procedures for it. After the tag attribute is connected, it appears in the Procedure drop-down list in the Code Editor window with the other standard events. You can select the template event and write code for it like you would any Visual Basic event.

A template event differs from a standard event in two main ways:

  • Template events are generated from an .htm file. A standard event is predefined and appears automatically for every template in the webclass. Because template events are generated from the HTML, you can have a different set of template events for each template file.

  • Template events must be connected before they can be programmed. Standard events are always available in the Code Editor window.

For More Information   See "Adding HTML Templates to the Webclass" for information on adding a template file to the webclass and viewing the tags that can act as events. See "Connecting Events in a Webclass" for instructions on connecting tags to events and webitems.