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

  • Question

  • 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


    • Edited by abnud1 Tuesday, February 20, 2018 2:15 PM
    • Moved by CoolDadTx Tuesday, February 20, 2018 2:47 PM ASP.NET related
    Tuesday, February 20, 2018 2:01 PM

All replies

  • Please post questions related to web development in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, February 20, 2018 2:47 PM
  • Since this is entirely client-side you should go to Internet Explorer Web Development. You should search for previous answers there. Also, search for articles and examples.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, February 20, 2018 10:02 PM