how to handle a c# activex event from javascript


  • I have this Test control :

    interface EventsInterface
        void myEvent();
    public partial class Test : UserControl
        public delegate void Event();
        public event Event myEvent;
        public Test()
        private void button1_Click(object sender, EventArgs e)

    Which only has one button.

    I'm testing the control in this html page:

    <!DOCTYPE html>
    <html lang="en" xmlns="">
        <meta charset="utf-8" />
        <object id="Control" classid="CLSID:0002EA9A-0BAF-4A9C-8300-7E4D7D371445"/>
        <script for="Control" event="myEvent()">

    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.

    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 ?

    I googled so much , all google results are telling me that my code is right.  

    I tried putting new keyword before my event and it didn't succeed. 

    Please help me , I'm stuck

    Monday, February 26, 2018 2:49 PM

All replies

  • Hi abnud1,

    According to your description, I guess you may not register the control  as COM.

    So it couldn't be used in html page.

    I suggest you could follow below article to know how to create ActiveX in .NET step by step. 

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, February 27, 2018 3:02 AM