如何在C#中使用windows控件库并在asp.net net中使用它 [英] How to use windows control library in C# and use it in asp.net net

查看:84
本文介绍了如何在C#中使用windows控件库并在asp.net net中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个带有两个按钮和一个文本框的Windows控件库。然后我将其dll复制到asp.net网站项目中。我能够在我的asp.net页面上看到我的windows控件。



现在当我尝试将windows控件的文本框值取入我的时候我遇到了问题asp.net页面的网页控制..



请帮忙吧。



windows控件代码



Hi,

I have created a windows control library with two buttons and a text box on it. Then I copied its dll into asp.net website project. I am able to see my windows control on my asp.net page.

Now I am facing problem when I am trying fetch value of windows control's text box value into my asp.net page's web control..

Please help its quite urgent.

Code of windows control

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsControlLibrary1
{

    public partial class tsControl : UserControl
    {
        public tsControl()
        {
            InitializeComponent();
        }
        public String st;
        [ComVisible(true)]
        public String tstString
        {
            get
            {
                return st;
            }
            set
            {
                st = value;
            }

        }
        private void btnSet_Click(object sender, EventArgs e)
        {
            tstString = txtSetValue.Text;
        }

        private void btnGet_Click(object sender, EventArgs e)
        {
            txtSetValue.Text = "2";
        }

        public void test()
        {

        }


    }
}







asp.net page






asp.net page

<tr>
                    <td>
                        <object classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.tsControl"

                            height="250" width="350" id="obj" />
                    </td>
                </tr>










<script language="JavaScript">
      <!--
         function doClick() {

            var val = document.getElementById('obj').tstString;
            alert(val);
         }
      // -->
      </script>

推荐答案

等一下?你希望在ASP.NET中使用 System.Windows.Forms 吗?如果是这样,就算了!;可能你不知道ASP.NET是如何工作的。



ASP.NET对客户端安装的软件没有任何假设。它通常使用Javascript,CSS和其他可通过通用Web浏览器读取的资源生成纯HTML。没有东西可以托管您的表格。所有.NET代码仅在服务器端托管;但是,如果你非常正式地在服务器端托管表单,谁会看到它们?你有提示吗?如果没有,请开始阅读ASP.NET的功能,但从HTTP服务器和客户端背后的基本思想开始。请参见 http://www.asp.net/get-started [ ^ ]。



-SA
Wait a minute? Are you hoping to use System.Windows.Forms in ASP.NET? If so, just forget it; probably you have no idea how ASP.NET works.

ASP.NET makes no assumption on the software installed in client. It normally generate plain HTML with Javascript, CSS and other resources readable with a general-purpose Web browser. There is nothing to host your Forms. All .NET code is hosted only on server side; but if you, quite formally, host the Forms on server-side, who will see them? Did you get the hint? If not, start reading about what ASP.NET does, but start from the very basic ideas behind HTTP servers and clients. See http://www.asp.net/get-started[^].

—SA


在Visual Studio中创建Windows控件库项目。 ...在其classid属性中,我们将控件的引用放在...中我们可以看到html页面中托管的控件:
Create a "Windows Control Library" project in Visual Studio. ... In its classid attribute we will place the control's reference in the ... We can see the control hosted in the html page:


1.创建这种类型的新项目,首先必须选择一种.NET语言 - 无论是C#,VB.NET还是C ++ / CLI都无关紧要。

2.然后,选择Windows类别缩小列出的项目类型的范围。

3.最后,选择名为Windows Forms Control Library的项目类型。

要了解更多,请查看此有用信息article。如何创建Windows控件库以及如何在C#.Net中使用
1.To create a new project of this type, you first have to pick one of the .NET languages—it doesn't matter which—either C#, VB.NET or C++/CLI.
2.Then, select the "Windows" category to narrow down the scope of the project types that are listed.
3.Finally, select the project type called "Windows Forms Control Library".
To know more check this useful article.How to Create Windows Control Library and how to use in C#.Net.


这篇关于如何在C#中使用windows控件库并在asp.net net中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆