简体   繁体   中英

Using windows control in web form

We have made a simple windows control which we want to use in web form.But we are not able to do it. we just found this solution in internet but this solution is not giving any output

Code for windows control

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

Implementation in webform :-

<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>

Would it not make more sense to create a custom web server control, and wrap the windows control within it? You could then expose all the properties and behaviour you wish, and use it as normal on ASP.NET.

More info on custom controls here:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM