Visual Basic Concepts
Connecting Events in a Webclass
HTML template files are made up of HTML tags, tag attributes, and text. HTML tags tell the system how to format and display the information on the page. Attributes provide additional detail about a specific item on the page. For example, for a picture in an HTML page, a tag called an IMG tag tells the system to format and display a picture. An attribute of that tag tells the system where to retrieve the picture from on the server.
When Visual Basic first adds a template to your webclass, it parses the file and lists all the tags for which one or more attributes can be treated as events. These attributes are not actual events, however, until they go through a process known as connecting. Prior to connection, it is more accurate to think of the tag attributes listed in the designer as event candidates.
You can connect an attribute in two ways:
You can connect the attribute to an event if you want to write code that tells the webclass how to respond when the element is processed by the browser. Elements are processed on the browser when the user selects the element or when the page processes them automatically, such as when it loads the page.
You can connect the attribute to a webitem if you want the element to activate a webitem and fire its Respond event when the element is processed in the browser.
Tip If you want to connect a button and program it, you must connect the button's FORM element rather than the button itself. You cannot access a button directly in your webclass code. If you have multiple buttons on a page and want to handle each separately in code, you can either use the Request object's Form collection to determine the button from which the event originated, or you can place each button in its own FORM element.
For More Information See "Webclass Events" for more information on adding events to a webclass and the types of events a webclass can process. See "Responding to Events in IIS Applications" for more information on writing code to process your events.
Connecting Attributes to Events
The template events in a webclass generally correspond to attributes of HTML tags in the template file. For example, an image event corresponds to an attribute of the IMG tag in the HTML page, and a hyperlink event corresponds to an A tag attribute in the HTML page. However, the association between attributes and events is not automatic — you must connect to events those tag attributes that you want to treat as events.
Connecting an attribute to an event enables the webclass to launch an event procedure when the end user selects the HTML element the tag attribute represents. For example, suppose you are working with a template called FeedbackPage. When you add this template to the webclass, Visual Basic parses the file and discovers that there are two elements within it capable of submitting requests to the server: a Submit hyperlink and a Home hyperlink. It lists the tags and attributes for these two elements in the designer's Detail panel. You can connect the attributes to events if you want them to fire events in your application.
Only connected events can be programmed. That is, after you connect an event, it appears in the Procedure drop-down list in the Code Editor window, and you can write procedures for it. Disconnected events do not appear in this list.
The Webclass Designer indicates the events that have not been connected in two ways:
Tags that have not yet been connected for the selected template appear in the Detail panel. After you connect an attribute, Visual Basic also displays the event in the Treeview panel, under the template to which it belongs, and displays the yellow lightning bolt icon for the event.
The Target column displays the word "<None>" for any disconnected tags. Once the tag has been connected to an event, the designer displays the name of the event in the Target column.
After you connect an attribute to an event, you can either write code for it in the Code Editor window, rename the event to which it is connected, or disconnect it. You might disconnect an event if you want to connect it to a webitem instead of to an event, or if you do not want it to function as an event. See "Connecting Attributes to a Custom WebItem" below for information on connecting to a webitem rather than an event.
To connect an attribute to an event
In the left panel of the Webclass Designer, click the template that contains the attribute you want to connect.
In the right panel of the Webclass Designer, right-click the attribute you want to connect, then select Connect to Event.
Visual Basic changes the text in the Target column to indicate that the attribute has been connected, and it displays the event in the tree view beneath the appropriate template.
To disconnect an attribute from an event
- Right-click the event in the right panel of the Webclass Designer, then click Disconnect.
Connecting Attributes to a Webitem
When you connect an attribute to a webitem rather than an event, you tell the webclass to activate that webitem when the HTML element the tag attribute represents is selected in the browser. When Visual Basic activates the webitem, it fires the webitem's Respond event. You must choose the specific webitem to which you want to connect the attribute.
For example, you might connect the attributes from a template file's IMG tag to a custom webitem that references an image stored on the server. When the user selects the element corresponding to the tag, it makes a call to the server that the webclass intercepts. The webclass tells Visual Basic to launch the associated webitem and fire its Respond event, which in turn retrieves the image from the database and returns it to the browser.
Visual Basic indicates that an attribute has been connected to a webitem in the Target column. Before you connect an attribute to a webitem, the word <None> appears in the Target column. After connection, the Target column displays the name of the webitem to which you connected the tag.
After you connect an attribute to a webitem, you can disconnect it and either leave it disconnected or connect it to another webitem. See "Connecting Attributes to Events" for more information on connecting to events.
To connect an attribute to a webitem
In the left panel of the Webclass Designer, click the template that contains the tag you want to connect.
In the right panel of the Webclass Designer, right-click the attribute you want to connect, then select Connect to Webitem.
In the Connect to WebItem dialog box, select the webitem to which you want to connect your tag attribute, then click OK.
Visual Basic displays the name of the webitem to which the attribute has been connected in the Target column.
To disconnect an attribute from a webitem
- Right-click the event in the right panel of the Webclass Designer, then click Disconnect.