Using Events in Windows Form Controls Hosted in IE

I have created a Windows Form Control that works successfully in Internet Explorer. I would like to give it an event and respond to the event via javascript. I found a link that talks about it here . It shows me how to create interfaces, but I'm not sure how to fire an out of control event?

Here's my code snippet:

//Control Code:
public class CardReader : Panel,ICardReaderEvents, ICardReaderProperties
{
   public void Error()
   {
   }
   public void Success()
   {
   }
}

//Interface for events
[Guid("DD0C202B-12B4-4457-9FC6-05F88A6E8BC5")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICardReaderEvents
{
    [DispId(0x60020000)]
    void Error();

    [DispId(0x60020001)]
    void Success();
}

//Interface for public properties/methods
public interface ICardReaderProperties
{
     ...
}

//JavaScript to handle events
<SCRIPT FOR="CardReader1" EVENT="Error">
    window.status = "Error...";
</SCRIPT>

<SCRIPT FOR="CardReader1" EVENT="Success">
    window.alert("Success");
    window.status = "";
</SCRIPT>

      

+1


source to share


2 answers


In your CardReader class, you are doing this incorrectly:

public event Error;
public event Success;

protected void OnError()
{
    if(Error != null)
        Error();
}

protected void OnSuccess()
{
    if(Success != null)
        Success();
}

      



If your ICardReaderEvents interface has changed to get errors and success, put them in OnError and OnSuccess.

+1


source


So now you need to know how to hook it up in Javascript? This is how I know how to do it:



<object id="CR" ...></object>

<script type="text/javascript">
  function CR::Error()
  {
    alert("Error!");
  }

  function CR::Success()
  {
    alert("Success");
  }
</script>

      

0


source







All Articles