Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. attach Event in Javascript

attach Event in Javascript

Scheduled Pinned Locked Moved C#
comcsharpjavascripthtmldatabase
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Navneet Hegde
    wrote on last edited by
    #1

    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 /tlb IN 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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups