Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate COM/ActiveXObject in C#, use from JScript, with simple event
    primarykey
    data
    text
    <p>I'd like to create a COM object in C#, and use it via IDispatch from JScript. That part is pretty simple.</p> <p>I also want to implement simple callbacks on the COM object, similar to the event exposed by the XmlHttpRequest object that is usable in a browser. That model allows Javascript to attach event handlers like this: </p> <pre><code>var xmlhttp = new ActiveXObject("MSXML.XMLHTTP"); xmlhttp.onReadyStateChange = function() { ... }; </code></pre> <p>I want my client-side JScript code to look like this: </p> <pre><code>var myObject = new ActiveXObject("MyObject.ProgId"); myObject.onMyCustomEvent = function(..args here..) { ... }; </code></pre> <p>What does the C# code look like? I'd like the general case - I'd like to be able to pass arguments back to the Javascript fn. </p> <hr> <p>I've seen <a href="https://stackoverflow.com/questions/1455577/how-can-i-make-an-activex-control-written-with-c-sharp-raise-events-in-javascrip/1456714#1456714">How can I make an ActiveX control written with C# raise events in JavaScript when clicked?</a> , but the answers there look really complicated to implement, and complicated to use. </p> <hr> <p>From <a href="http://rageshkrishna.com/blog/2008/05/14/ImplementingActiveXEventsThatCanBeUsedInJavaScript.aspx" rel="nofollow noreferrer">this article</a>, it seems that XMLHttpRequest events are not COM events. The <code>onreadystatechange</code> is a property of type <code>IDispatch</code>. When script clients set that property to a function, JScript marshals it as an IDispatch object. </p> <p>The only problem that remains is then to invoke the IDispatch from C#. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload