First I'd like to say that I've seen these two questions :
How to handle an ActiveX event in Javascript
How can I make an ActiveX control written with C# raise events in JavaScript when clicked?
Now I have this Test control :
interface EventsInterface
{
[DispId(0)]
void myEvent();
}
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(EventsInterface))]
[Guid("0002EA9A-0BAF-4A9C-8300-7E4D7D371445")]
public partial class Test : UserControl
{
public delegate void Event();
public event Event myEvent;
public Test()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
myEvent();
}
}
Which only has one button.
I'm testing the control in this html page:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<object id="Control" classid="CLSID:0002EA9A-0BAF-4A9C-8300-7E4D7D371445"/>
<script for="Control" event="myEvent()">
alert("hello");
</script>
</body>
</html>
When I click the button in IE 8 it's supposed to alert("hello")
but instead it throws a NullPointerException that myEvent is null So this means the event handler is not set from javascript.
Why doesn't it work ? and how to make it work ?.
By the way I'm testing the page using the 64bit version of IE on windows 7.
Edit
I tried signing my assembly but it didn't work, all my googling reveals that my code is right so why isn't it working ? what should I do ?