I am trying to develop a Windows Forms user control to be embedded in IE 8.
The control is showing fine, but I can't fire an event that I can catch in JavaScript.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security.Permissions;
[assembly: ClassInterface(ClassInterfaceType.AutoDual)]
namespace ASPNETBasicsWorkshop.Windows.Forms.UserControl
{
[Guid("C76FFA39-6EDF-49a5-A825-C66B1E4FC32C")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMyControlData
{
String MyData
{
get;
set;
}
}
[Guid("2c4b843f-9c5e-4bc0-83c3-2e2e928f6815")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMyControlEvents
{
[DispId(0x0)]
void MyEvent();
}
public delegate void MyEventHandler();
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IMyControlEvents))]
public partial class MyControl : System.Windows.Forms.UserControl, IMyControlData
{
public MyControl()
{
}
public event MyEventHandler MyEvent;
[SecurityPermission(SecurityAction.Assert, Unrestricted = true, UnmanagedCode = true)]
protected void OnMyEvent()
{
if (this.MyEvent != null)
{
this.MyEvent();
}
}
protected override void OnLoad(EventArgs e)
{
Button button = new Button();
button.Name = "MyButton";
button.Text = "Click Me";
button.Click += MyButton_Click;
this.Controls.Add(button);
base.OnLoad(e);
}
private void MyButton_Click(Object sender, EventArgs e)
{
this.OnMyEvent();
}
public String MyData
{
get;
set;
}
}
}
And my HTML:
<%@ Page Language="C#" MasterPageFile="~/Site.Master" CodeBehind="Controls.aspx.cs" Inherits="ASPNETBasicsWorkshop.Controls" %>
<asp:Content ContentPlaceHolderID="body" runat="server">
<object id="MyControl" classid="http:ASPNETBasicsWorkshop.Windows.Forms.UserControl.dll#ASPNETBasicsWorkshop.Windows.Forms.UserControl.MyControl" width="300" height="200">
</object>
<script type="text/javascript" for="MyControl" event="MyEvent">
window.status = 'Selection: ' + window.document.getElementById('CustomControl').SelectionStart + ' to ' + window.document.getElementById('CustomControl').SelectionEnd;
</script>
</asp:Content>
Whenever I click on the button, I get a security exception on method OnMyEvent. I've tried adding a SecurityPermissionAttribute, but no luck.
Any ideas?
Thanks,
Ricardo Peres