locked
how to handle a c# activex event from javascript RRS feed

  • Question

  • User-2011553829 posted

    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.

    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

    Tuesday, February 20, 2018 2:52 PM

All replies