javascript, new ActiveXObject() and events

G

Guest

Hello,
I have an ActiveX object with events, and I need to get notifications of
these events in javascript script on asp.net web page.
The mentioned above ActiveX is a standard ATL com object implementing event
interface:
dispinterface _MyEvents
{
properties:
methods:
[id(1), helpstring("method MyEvent")] void MyEvent([out]BSTR aData);
};

Is it possible to subscribe to that event when the object is dynamically
created with "var obj = new ActiveXObject("...")"? There's a lot of info
about events when object is embedded into the page, but I can't find any
decent info about events of dynamically created objects.

Thanks in advance for any help.
 
A

Alvin Bruney [MVP]

about events when object is embedded into the page, but I can't find any
decent info about events of dynamically created objects.

It follows the same pattern. You need to do a couple of things:
Make sure IIS is configured correctly.
Make sure the ActiveX control supports eventing - delegates and events
are wired correctly for .net usercontrols.
make sure the assembly is COM visible.
For unmanaged controls, this should all be done already so you can skip it.

If all the plumbing is setup correctly, you'll need to map the script from
the client like so - assuming ClickEvent is an event in the activex control:

<script for=myControl1 event="ClickEvent(a,b)" language="javascript">
function myControl1::ClickEvent(a,b)

{

alert('Events are firing in Internet Explorer with co-ordinate: ' + a);

}

</script>

For dynamic controls, simply write out the script into the body of the html
document. The end result for both process should be the fully formed script
tag in the page when you view the html source.

That's about it. If the control is a managed user control embedded in a web
form, you will need two more things:
1. Configure CAS for the application.
2. In script, tell IIS where to find the control roughly:
<OBJECT id="myControl1" name="myControl1"
classid=http://server.com/ActiveX.dll#ActiveX.POCUserControl1> </OBJECT>


--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET - MS Press
Professional VSTO 2005 - Wrox/Wiley
OWC Black Book www.lulu.com/owc

Eugene said:
Hello,
I have an ActiveX object with events, and I need to get notifications of
these events in javascript script on asp.net web page.
The mentioned above ActiveX is a standard ATL com object implementing
event
interface:
dispinterface _MyEvents
{
properties:
methods:
[id(1), helpstring("method MyEvent")] void MyEvent([out]BSTR aData);
};

Is it possible to subscribe to that event when the object is dynamically
created with "var obj = new ActiveXObject("...")"? There's a lot of info
about events when object is embedded into the page, but I can't find any
decent info about events of dynamically created objects.

Thanks in advance for any help.
 
G

Guest

Alvin Bruney said:
<script for=myControl1 event="ClickEvent(a,b)" language="javascript">
function myControl1::ClickEvent(a,b)

{

alert('Events are firing in Internet Explorer with co-ordinate: ' + a);

}

</script>
That doesn't seem to work, as I have just a variable named MyObj but not an
object with ID="MyObj".

my javascript code:

var MyObj;

function PageLoad()
{
try
{
MyObj = new ActiveXObject("MyLib.MyObject");
MyObj.Open(1);
}
catch (e)
{
alert(e);
}
}

function PageUnLoad()
{
try
{
if (MyObj.IsActive)
{
ScanApp.Close();
}
MyObj = null;
}
catch (e)
{
alert(e);
}
}


So when I add "function MyObj::OnBarcodeRead(aBarcode){ alert(aBarcode); }"
the outcome is predictable "Error: Object expected".

What I need is a mechanism like Advise to bind a javascript function to COM
object event.
 
G

Guest

Well, it seems like there's no way of usingstandard events with the objects
created by "new ActiveXObject" technique.

It's still possible to call javascript methods from ActiveX using
IDispatch.Invoke supplied via ole object properties, f.e. like Microsoft
does in their XMLHTTP object. It does essentially what I wanted to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top