在网页上添加Windows窗体用户控件:错误:未指定控件类型或找不到指定的类型 [英] Adding a Windows Form User Control on a Web page: Error: a control type was not specified or the specified type could not be found
问题描述
我创建了一个Windows窗体用户控件dll.该控件有一个按钮和一个图片框.我使用以下代码将其添加到我的.aspx页面:
I created a windows form user control dll. The control has a button and and a picturebox. I added it to my .aspx page using this:
<object id="MyWinControl1" height="200" classid="http:WindowsFormsControlLibrary1.dll#WindowsFormsControlLibrary1.UserControl1" VIEWASTEXT> </object>
我把它放在我的身体标签之间.
在设计视图中,我收到此错误:
未指定控件类型或找不到指定的类型
我究竟做错了什么?我需要提供更多信息吗?
[OPs答案移至此处]
这是我的代码:
UserControl1.cs:
I put it in between my body tag.
In design view I get this error:
a control type was not specified or the specified type could not be found
What am I doing wrong? Do I need to put more information?
[OPs Answer moved to here]
This is my code:
UserControl1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsControlLibrary1
{
[ComVisible(true)]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void SendMessage(string msg)
{
lblMessage.Text = msg;
}
}
}
HTMLPage1.htm
HTMLPage1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Windows Form Control Test Page</title>
<script type="text/javascript">
function SendMessageToWinControl() {
var winCtrl = document.getElementById("MyWinControl");
winCtrl.SendMessage("Message sent from the HTML page!!");
}
</script>
</head>
<body>
<h1>Windows Form Control:</h1>
<object id="MyWinControl" classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1"
height="100" width="300" VIEWASTEXT/>
<br/><br/>
<input type="button" onclick="SendMessageToWinControl()" value="Send Message" />
</body>
</html>
当我在设计视图中查看HTMLPage1.htm时.应该显示控件的地方说:
When I look at the HTMLPage1.htm in design view. Where it is suppose to show the control it says:
a control type was not specified or the specified type could not be found
而且我没有看到应该显示的按钮.
当我在浏览器中查看HTMLPage1.htm时,我会看到一个红色的X,该X应该位于我的控件处.而且我没有看到应该显示的按钮.
and i don''t see the button that is suppose to show.
When I view HTMLPage1.htm in the browser I see a red X where my control is suppose to be at. And I don''t see the button that is suppose to show.
推荐答案
我从来没有尝试过自己做过,但是我确实找到了这个小教程,声称可以办到.
托管Windows表单网页中的控件
我是通过
I have never tried to do this myself, but I did find this little tutorial that claims it can be done.
Hosting a Windows Form Control in a web page
I found it with this google search.
这篇关于在网页上添加Windows窗体用户控件:错误:未指定控件类型或找不到指定的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!