Defining Custom Events

MS Office DHTML, HTML & CSS

 
Click to return to the Component Development home page    
Welcome to Scriptlet Tech...    

Defining Custom Events


You can use custom events to:

  • Send more detail about a standard event—for example, which of the buttons in the scriptlet was clicked.
  • Notify the host application about DHTML events that are not among the standard events handled by the bubbleEvent method.
  • Notify the host application about nonstandard changes in the scriptlet, such as when the value of a property changes.

As with standard events, you must send the event from the scriptlet and capture the event in the host application.

To send a custom event in the scriptlet:

  • Call the scriptlet's raiseEvent method.

    Note Before passing events to the container object, you can check the scriptlet's frozen property to be sure that the container object is ready to handle events.

For example, the following shows how you can send a custom event called oncolorchange whenever the scriptlet's backgroundColor property is reset.

<SCRIPT LANGUAGE="JavaScript">
function public_put_backgroundColor(value)
{
   window.document.bgColor = value;
   window.external.raiseEvent("event_onbgcolorchange",window.document);
}
</SCRIPT>

To handle a custom event in the host application:

The following is an example in Microsoft® Visual Basic® that shows how you can determine which control triggered an event.

Sub ScriptletContainer1_onscriptletevent( ByVal txtTitle As String, _
ByVal eventData As Variant) objName = eventData.srcElement.ID MsgBox "The event " & txtTitle & " occurred in " & objName End Sub

If your host application is Microsoft Internet Explorer, use a script such as the following to capture the scriptlet event.

<SCRIPT   LANGUAGE="JavaScript" 
FOR=ScriptletControl1
EVENT= onscriptletevent (name, eventData)> alert("The event that occurred in the scriptlet was " + name); </SCRIPT>

You can use a Select Case structure in the onscriptletevent event to take different actions based on different events.

See Also

Handling Standard Events



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.