How can I pass Javascript function into .NET control?

M

mdb

I have a .NET control that I have built and embedded in a web page, as
described in the link below. I am having great success in getting it to do
what I want, but one thing I haven't been able to figure out is how to
subscribe to events that are built into the .NET control.

[http://www.c-sharpcorner.com/Code/2003/March/ActiveXInNet.asp]

I have added a function Subscribe(...), something like this:

public delegate void Func_Delegate(string v);
public event Func_Delegate MyEvent = null;
public void Subscribe(Func_Delegate fPtr)
{

MyEvent += fPtr;
}

and in my web page, I call in javascript:

var fPtr = MyEventHandler
myObject.Subscribe(fPtr);

but this results in a javascript error "Class doesn't support automation".

If I change the Subscribe function to:

public void Subscribe(object x)
{
MessageBox.Show(x.GetType().FullName);
}

then it reports that the type is 'System.__ComObject'. If I can somehow
cast this to something that I can use, then this would be fine, but I
haven't been able to figure out what to cast it to. If I pass the
'document' element, then I can see that it is an 'IHtmlDocument2', and I
can cast it as such and access all the items, but I don't see how I can run
a script function from this object. The function pointer isn't anything
that is in the Microsoft.JScript or MSHTML namespaces (I iterated over each
type in these assemblies looking for a type match, but found none - but it
did find the IHtmlDocument2, so I know it is working.)

Does anyone have any suggestions or information resources that can assist
in this? Is this even possible? Again, I'm trying to call a Javascript
function from within the .NET embedded object.

Also, is there a better newsgroup to post this question in? Thanks!
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top