HtmlObject.AttachEvent Method (String, EventHandler)
Attaches the specified .NET Framework event handler (EventHandler) to the specified event on the current Document Object Model (DOM) object.
Assembly: System.Windows.Browser (in System.Windows.Browser.dll)
- Type: System.String
A named event on the DOM object.
- Type: System.EventHandler
The method that handles the event.
Return ValueType: System.Boolean
true if the event was successfully attached; otherwise, false.
Events can be sent into managed code from DOM elements or HTML objects (such as the window object) in two ways:
An element can immediately send an event into managed code.
An element can trigger an event that bubbles up through the DOM hierarchy until it reaches an element that is capable of sending the event into managed code.
Therefore, the sender parameter value can be different from the Source property value.
Cross-browser event naming issues are handled as follows:
For Internet Explorer: If eventName does not start with the string "on", the string is prepended to the event name (for example, "click" is changed to "onclick"). This enables developers who want to use Firefox naming conventions to attach their events automatically in Internet Explorer.
For other browsers: If eventName starts with the string "on", the string is removed from the event name to support browsers that have different naming conventions. (For example, "onclick" is changed to "click, and "onblur" is changed to "blur".)
No action is taken if the event that is specified in eventName does not exist.
To obtain a reference to the DOM element that raised the event, use the AttachEvent(String, EventHandler<HtmlEventArgs>) method.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.