views:

1510

answers:

1

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

What I'm doing:

Public Class ctrlABC
   Public Event TestEvent()

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

RaiseEvent TestEvent()

In my JS file, I've 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 neither seems to get the event. Does anyone have any ideas?

Thanks!

+1  A: 

I've not used <object>'s like that so I cant be sure, but I would expect you declare the event handler like regular events in Javascript.

In the elements attributes:

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

or as a function in the object: (might not be the correct term)

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

or using the event registration function(s): document.getElementById("myControl1").addEventListener("TestEvent", functionName, false);

(these are browser specific, this one is for firefox, not sure about others)

with each of these "functionName" is a function you declare in the <head>.

Might want to have a look at Quirksmode - Advanced event registration

NickSlash
hmm, probably should have paid more attention to the date.
NickSlash