Good day all!!!
I have been trying to create a windows form control to host in a webpage. Code below:
using System;
using System.Data;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace WindowsFormsControlLibrary2
{
[ComVisible(true)]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void SendMessage(string msg)
{
_lblMessage.Text = msg;
}
}
}
HTML file looks like this. Code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Windows Form Control Test Page</title>
<script type="text/javascript">
function SendMessageToWinControl()
{
var winCtrl = document.getElementById("MyWinControl");
console.log(winCtrl);
winCtrl.SendMessage("Message sent from the HTML page!!");
}
</script>
</head>
<body>
<h1>Windows Form Control:</h1>
<object id="MyWinControl" classid="http://localhost/WindowsFormsControlLibrary2.dll#WindowsFormsControlLibrary2.UserControl1" height="100" width="300" VIEWASTEXT></object>
<br/><br/>
<input type="button" önclick="SendMessageToWinControl()" value="Send Message" />
</body>
</html>
I'm putting both the html and dll files in my wwwroot folder. But I'm not seeing the control. If I click on the "SendMessageToWinControl" button, while firebug is open, it gives me the following error:
Object doesn't support property or method SendMessage;
test.html, line 13 character 6
Even when I copy the code from:
winform control hosting to webform[
^]
It's not working. I'm using VS2010 C#4.0