attach Event in Javascript
C#
1
Posts
1
Posters
0
Views
1
Watching
-
Hi All!
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace FinalEventsDLL
{
public delegate void ControlEventHandler(string redirectUrl);\[Guid("E819B536-D64F-4fed-BCE7-F21650364211")\] public interface DBCOM\_Interface { \[DispId(1)\] void Hello1(string userid, string password); \[DispId(2)\] bool Hello2(string selCommand); } // // Events interface Database\_COMObjectEvents \[Guid("E72E89DB-788B-4f6d-BFB1-679CC103D13A"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)\] public interface DBCOM\_Events { //Add a DispIdAttribute to any members in the source interface to specify the COM DispId. \[DispId(0x60020001)\] void OnClose(string redirectUrl); //This method will be visible from JS } \[Guid("EC393ACC-37A5-44da-B316-E4E367517D1C"), ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(DBCOM\_Events))\] public class FinalDLL : DBCOM\_Interface { public FinalDLL() { } public event ControlEventHandler OnClose; public void Hello1(string userid, string password) { return; } public bool Hello2(string selCommand) { Close(); return true; } \[ComVisible(true)\] public void Close() { if (OnClose != null) { OnClose("http://otherwebsite.com"); //Calling event that will be catched in JS } else { MessageBox.Show("No Event Attached"); //If no events are attached send message. } } }
}
Above is the code for my C# DLL
REGISTERED
I have registered it using regasm D:\FinalEventsDLL.ddl /codebase /tlbIN JAVASCRIPT
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title>C# ActiveX Test</title> </head><body onload="myload();">
<h1>This is Our ActiveX Test Page h1><script type="text/javascript" >
function myload{
var myAx = new ActiveXObject("FinalEventsDLL.FinalDLL");if(myAx != null) { myAx.Hello2("sd") } else { alert("NOOOO... we failed"); }
}
</script></body></html>
Everything is work