Wednesday, August 02, 2006

HTC


A HTC file is nothing but an HTML file, saved with a .htc extension. It contains scripts and a set of HTC-specific custom elements, that define the component.

Objects:
document - the HTML document in a given browser window
PUBLIC: ATTACH - binds a function to an event
PUBLIC: COMPONENT - identifies the content of the file as HTC
PUBLIC: DEFAULTS - sets default properties for an HTC
PUBLIC: EVENT - defines an event
PUBLIC: METHOD - defines a method
PUBLIC: PROPERTY - defines a property of the HTC
element - returns a reference to the tag in the primary document, to which the behavior is attached

exp.
attaching behavior to a simple asp TextBox:
TextBox _myTextBox;
...
_myTextBox.Style.Add("behavior","url(myhtcfile.htc)");

where the HTC file should look like this:
<PUBLIC: COMPONENT>
<PUBLIC: PROPERTY name="propertyName" />
<PUBLIC: ATTACH event="eventName" handler="MyEventHandler"/>
...
<SCRIPT language="JScript">
function MyEventHandler()
{ ... }
</SCRIPT>
</PUBLIC: COMPONENT>

and the file name should be:
myhtcfile.htc

No comments: