Click here to Skip to main content
15,889,315 members
Home / Discussions / C#
   

C#

 
QuestionBest Practice Advice - Eschewing Web Services? Pin
Jasmine Pomelo18-Mar-09 6:51
Jasmine Pomelo18-Mar-09 6:51 
QuestionDataset Selection Pin
Stefano Negro18-Mar-09 5:40
Stefano Negro18-Mar-09 5:40 
AnswerRe: Dataset Selection Pin
Xmen Real 18-Mar-09 6:16
professional Xmen Real 18-Mar-09 6:16 
GeneralRe: Dataset Selection Pin
Stefano Negro19-Mar-09 0:32
Stefano Negro19-Mar-09 0:32 
AnswerRe: Dataset Selection Pin
Mohammad Dayyan18-Mar-09 6:31
Mohammad Dayyan18-Mar-09 6:31 
AnswerRe: Dataset Selection Pin
tech60318-Mar-09 14:44
tech60318-Mar-09 14:44 
AnswerRe: Dataset Selection Pin
jaypatel51218-Mar-09 19:23
jaypatel51218-Mar-09 19:23 
Questionattach Event in Javascript Pin
Navneet Hegde18-Mar-09 5:39
Navneet Hegde18-Mar-09 5:39 
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 working fine so far ,problem is
myAx.Hello2("sd")
when I call this event OnClose DLL event is fired, But how can I catch this in Javascript

I tried GOOGLE and Other Stuff's but not getting any proper answer

I also tried

function myAx::OnClose(redirectionUrl)
{alert();}

But this doesn't seems to work

Can you please help me get the proper way to Catch DLL Event in Javascript

Thanks!

Develop2Program & Program2Develop
QuestionNearest point on a line. Pin
Steve_18-Mar-09 4:58
Steve_18-Mar-09 4:58 
AnswerRe: Nearest point on a line. [modified] Pin
musefan18-Mar-09 5:00
musefan18-Mar-09 5:00 
QuestionRe: Nearest point on a line. Pin
12Code18-Mar-09 5:19
12Code18-Mar-09 5:19 
AnswerRe: Nearest point on a line. Pin
musefan18-Mar-09 5:26
musefan18-Mar-09 5:26 
GeneralRe: Nearest point on a line. Pin
moon_stick18-Mar-09 5:54
moon_stick18-Mar-09 5:54 
GeneralRe: Nearest point on a line. Pin
musefan18-Mar-09 6:03
musefan18-Mar-09 6:03 
AnswerRe: Nearest point on a line. Pin
led mike18-Mar-09 5:01
led mike18-Mar-09 5:01 
AnswerRe: Nearest point on a line. Pin
moon_stick18-Mar-09 5:08
moon_stick18-Mar-09 5:08 
AnswerRe: Nearest point on a line. Pin
harold aptroot18-Mar-09 5:25
harold aptroot18-Mar-09 5:25 
Questionmerge using C# Pin
StoneCOLD70918-Mar-09 4:44
StoneCOLD70918-Mar-09 4:44 
AnswerRe: merge using C# Pin
musefan18-Mar-09 4:58
musefan18-Mar-09 4:58 
GeneralRe: merge using C# Pin
StoneCOLD70918-Mar-09 6:29
StoneCOLD70918-Mar-09 6:29 
GeneralRe: merge using C# Pin
musefan18-Mar-09 6:44
musefan18-Mar-09 6:44 
GeneralRe: merge using C# Pin
StoneCOLD70918-Mar-09 7:15
StoneCOLD70918-Mar-09 7:15 
GeneralRe: merge using C# Pin
musefan18-Mar-09 7:28
musefan18-Mar-09 7:28 
GeneralRe: merge using C# [modified] Pin
StoneCOLD70918-Mar-09 8:04
StoneCOLD70918-Mar-09 8:04 
Questionerror while inserting table with autonumber using MsAccess Pin
sakthi06karthi18-Mar-09 3:51
sakthi06karthi18-Mar-09 3:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.