在web窗体中使用windows控件

本文关键字:windows 控件 web 窗体 | 更新日期: 2023-09-27 18:29:49

我们制作了一个简单的窗口控件,我们想在web窗体中使用它。但我们无法做到。我们刚刚在互联网上找到了这个解决方案,但这个解决方案没有提供任何输出

窗口控制代码

<pre lang="cs">namespace WinformUsrCntl
 {
[ComVisible(true)]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
  InitializeComponent();
}
public void setText(string text)
{
  label1.Text = text;
}
}
}</pre>

网络表单中的实现:-

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Defualt</title>
<script type="text/javascript">
 function SendMessageToWinControl() {
 var winCtrl = document.getElementById("myName");
 winCtrl.innerHTMl("Message sent from the HTML page!!");
 }       
</script>
<style type="text/css">
</head>
<body>
<form id="form1" runat="server">
<div>
 <h1>
    Windows Form Control:</h1>
   <input type="button" onclick="SendMessageToWinControl()" value="Send Message" />
       <br/>
    <object id="myName" width="100px"               classid="http:WinformUsrCntl.dll#WinformUsrCntl.UserControl1"
       VIEWASTEXT />
</div>
</form>
  </body>
  </html>

在web窗体中使用windows控件

创建一个自定义的web服务器控件并将windows控件封装在其中是否更有意义?然后,您可以公开您想要的所有属性和行为,并在ASP.NET上正常使用它。

有关自定义控件的更多信息,请点击此处:

http://msdn.microsoft.com/en-us/library/zt27tfhy(v=vs.100).aspx