0

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 ?

4
  • You need to declare a delegate and and event which inherit that delegate. Also, you must check before calling the delegate if it's not null to avoid NullReferenceExceptions.. See: learn.microsoft.com/en-us/dotnet/standard/events Commented Feb 19, 2018 at 13:12
  • 5
    IE8 + ActiveX? My deepest condolences. Commented Feb 19, 2018 at 13:12
  • @Oscar I didn't understand you, could you give me an example ? Commented Feb 19, 2018 at 13:47
  • @Andreas I could use IE 11 fortunately but there is no escape from ActiveX, condolences accepted Commented Feb 19, 2018 at 13:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.