Click here to Skip to main content
15,868,161 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Good day all!!!

I have been trying to create a windows form control to host in a webpage. Code below:

C#
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:

HTML
<!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
Posted
Updated 1-Mar-13 0:43am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900