Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

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

XML
<tr>
                    <td>
                        <object classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.tsControl"
                            height="250" width="350" id="obj" />
                    </td>
                </tr>



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

            var val = document.getElementById('obj').tstString;
            alert(val);
         }
      // -->
      </script>
Posted
Updated 21-Sep-16 22:05pm
Comments
Syed Salman Raza Zaidi 27-Jul-11 2:02am    
Try Adding Reference of you DLL from Solution explorer in your web application
walterhevedeich 27-Jul-11 2:25am    
What exactly is the problem? Does it throw an error? Perhaps you need to describe more.
Sergey Alexandrovich Kryukov 27-Jul-11 2:31am    
Tag it properly. "WinForms", not "Windows".
--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
 
Share this answer
 
Comments
Gordon Beeming 27-Jul-11 15:46pm    
Apparently it is possible to get this to work, I'm yet to do it myself though
Sergey Alexandrovich Kryukov 14-Sep-11 9:51am    
Doing it yourself is really a decent decision, I appreciate it.

However, what would be the sense of running Forms in ASP.NET. The code the .NET code, hence it would run of server side, and the form would be shown on server side. Who will see them?

Also, you can use some Forms code as application using COM component and <object> tag in HTML, client side, but who needs it, only Windows user careless enough to install some code from Web page? This is not a pure Web solution, should always be avoided.
--SA
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:
 
Share this answer
 
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.
 
Share this answer
 
Comments
Richard MacCutchan 22-Sep-16 4:26am    
Why are you posting in a FIVE year old question?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900