Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 17

Creating and Programming Custom WebItems - Custom Events for WebItems

Each custom WebItem that you define automatically gets its own Response event, as discussed in the preceding section. You can, however, define one or more events of your own for a WebItem. You can then embed calls to these events in the HTML code that you return to a browser by using a slightly different syntax for the URLFor function from that discussed in the preceding section. To implement a custom WebItem event, take the following steps:

STEP BY STEP
17.3 Implementing a Custom WebItem Event

  1. After you have created a custom WebItem, right-click it in the IIS project and choose Add Custom Event from the resulting ShortCuts menu.

  2. A new event will be added to the WebItem and will appear underneath the WebItem in the tree with a lightning-bolt icon. It will have a generic name, which you can change by right-clicking the event item and choosing the Rename option from the shortcut menu.

  3. You can embed an invocation of the event in the HTML code that you return to the browser by using the URLFor function in the Start event procedure of the WebClass. This technique is similar to that discussed in step 4 in the preceding section. However, the syntax that you will use with the URLFor function differs slightly from that of the preceding example. In the case of a custom event, you must pass the URLFor function two arguments rather than just one. The first argument will still be the name of the WebItem, and the new second argument will be a string giving the name of the custom event.

    Listing 17.11 gives a fragment of code from a WebClass’ Start event procedure that uses the URLFor function to embed a hyperlink to a WebItem’s custom event,

    LISTING 17.11
    CODE IN WEBCLASS_START THAT EMBEDS A HYPERLINK FOR A CUSTOM EVENT OF A WEBITEM IN THE HTML RETURNED TO THE BROWSER


    With Response
    .Write "<A HREF=""" & _
    URLFor(SvcResponse,"Excellent") & _
    """>Excellent</A><BR>"
    End With

    The code assumes that a custom event named Excellent belongs to a WebItem named SvcResponse.

  4. You would use a similar technique to that discussed in step 5 in the preceding section to react to the user’s activation of the event’s hyperlink. Instead of writing code in the Respond event (as the preceding example shows), you would rather write code in the event procedure named for the custom event that you yourself had defined.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved