Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

javascript, new ActiveXObject() and events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eugene - 14 Aug 2007 15:48 GMT
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.
Alvin Bruney [MVP] - 15 Aug 2007 00:27 GMT
> 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>

Signature

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

> Hello,
> I have an ActiveX object with events, and I need to get notifications of
[quoted text clipped - 15 lines]
>
> Thanks in advance for any help.
Eugene - 15 Aug 2007 08:30 GMT
> <script for=myControl1 event="ClickEvent(a,b)" language="javascript">
> function myControl1::ClickEvent(a,b)
[quoted text clipped - 6 lines]
>
> </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.
Eugene - 15 Aug 2007 14:50 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.