How to raise events from VB.Net ClassLibrary / UserControl (ActiveX) to JavaScript?

I created a VB.Net ClassLibrary in it with UserControl. I can load it from an HTML page and call the methods that I created. This works as expected. I tried some examples of how to raise an event from VB code in js-caller, and none of them work (I use IE7).

What am I doing:

Public Class ctrlABC
   Public Event TestEvent()

Then, when I want to raise this event, I call:

RaiseEvent TestEvent()

In my JS file, I tried the following:

<OBJECT id="myControl1" name="myControl1" classid="ABC.dll#ABC.ctrlABC" width=400 height=400></OBJECT>

<SCRIPT LANGUAGE=javascript FOR=myControl1 EVENT=TestEvent> 
    myControl1_TestEvent()  
</SCRIPT>

<script>
function myControl1_TestEvent(){
    alert("raised");
}
</script>

==================== and then I tried ====================

<OBJECT id="myControl1" name="myControl1" classid="ABC.dll#ABC.ctrlABC" width=400 height=400></OBJECT>

<script>
function myControl1::TestEvent(){
    alert("raised");
}
</script>

=============================

but it does not seem to be an event. Does anyone have any idea?

Thanks!

+3
source share
1 answer

<object> , , , Javascript.

:

<object id="myControl1" .... onTestEvent="functionName"></object>

: ( , )

document.getElementById("myControl1").onTestEvent = functionName

() : document.getElementById("myControl1").addEventListener("TestEvent", functionName, false);

( , Firefox, )

"functionName" - , <head> .

, Quirksmode -

+1

Source: https://habr.com/ru/post/1709129/


All Articles