title: How to handle an ActiveX event in Javascript
body: <p>This is somewhat of a follow-up to an answer <a href="https://stackoverflow.com/questions/26536/active-x-control-javascript">here</a>.</p>
  
  <p>I have a custom ActiveX control that is raising an event ("ReceiveMessage" with a "msg" parameter) that needs to be handled by Javascript in the web browser. Historically we've been able to use the following IE-only syntax to accomplish this on different projects:</p>
  
  <pre><code>function MyControl::ReceiveMessage(msg)
  {
     alert(msg);
  }
  </code></pre>
  
  <p>However, when inside a layout in which the control is buried, the Javascript cannot find the control. Specifically, if we put this into a plain HTML page it works fine, but if we put it into an ASPX page wrapped by the <code>&lt;Form&gt;</code> tag, we get a "MyControl is undefined" error. We've tried variations on the following:</p>
  
  <pre><code>var GetControl = document.getElementById("MyControl");
  function GetControl::ReceiveMessage(msg)
  {
     alert(msg);
  }
  </code></pre>
  
  <p>... but it results in the Javascript error "GetControl is undefined."</p>
  
  <p>What is the proper way to handle an event being sent from an ActiveX control? Right now we're only interested in getting this working in IE. This has to be a custom ActiveX control for what we're doing.</p>
  
  <p>Thanks.</p>