Reputation: 8141
From another question I recently posted, it seems that Classic ASP might not be able to deal with events that an activeX object might throw.
Can anybody verify this or if it can, how do I do it?
Upvotes: 2
Views: 539
Reputation: 192437
Is it possible to handle events from an activeX object in Classic ASP
No, if you are speaking about COM events.
But, Depending on what you mean by the word "event" the answer is "Maybe."
See Create COM/ActiveXObject in C#, use from JScript, with simple event
It's possible to create a COM class / ActiveX thing, instantiate it in JScript/Classic ASP, and have the COM class invoke a callback that is defined in the ASP page. This is not done via COM events, but it may satisfy your requirement.
The ASP code might look like:
<script language="Javascript" runat="server">
var greet = Server.CreateObject("Ionic.Greet");
greet.onHello = function(arg, num) {
Response.Write("onHello (ASP) invoked.<br/>\n");
Response.Write(" num = " + num + " stat=" + arg.status + "<br/>\n");
};
response = greet.Hello("ASP");
Response.Write("response: " + response + "<br/>\n");
Response.Write("status: " + greet.status + "<br/>\n");
</script>
This works only if the COM class being created exposes a property that can be set, and then invokes the "Default method" on that property. Like this:
public partial class Greet : IGreet
{
public Object onHello { get; set; }
public String Hello(string name)
{
var r = FireEvent();
return "Why, Hello, " + name + "!!!" + r;
}
}
...where FireEvent is like this:
private string FireEvent()
{
if (onHello == null) return " (N/A)";
onHello
.GetType()
.InvokeMember
("",
BindingFlags.InvokeMethod,
null,
onHello,
new object [] {});
return "ok";
}
Obviously if you have a COM class that cannot be changed, and it uses COM events, then this approach will not apply.
Upvotes: 1
Reputation: 189437
You are correct ASP cannot handle events. It does not have the either the CreateObject
signature needed to wire up script functions to events nor does it support the <script FOR
syntax that you might use client-side.
Upvotes: 1