Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Posted 1-Mar-13 1:41am
azinyama1.2K
Edited 1-Mar-13 1:43am
v2

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

  Print Answers RSS
0 OriginalGriff 562
1 Sergey Alexandrovich Kryukov 484
2 Maciej Los 325
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100