Click here to Skip to main content
15,174,850 members
Articles / Web Development / HTML
Posted 13 Feb 2005


46 bookmarked

A very easy .NET “Applet”

Rate me:
Please Sign up or sign in to vote.
3.16/5 (17 votes)
13 Mar 2005CPOL2 min read
Make a Windows Forms UserControl work like an Applet.

Sample Image - CSharpApplet.gif


Some time ago, I needed my web application to interact with a specific hardware in the computer, but I didn't want to write an ActiveX, I wanted to write it in a .NET language. So I made a search in the web and I found some examples that helped me on that. In this article I will use a UserControl as an applet on my .htm page.

This example of "applet" doesn't make anything relevant. It's only to show how to put a Windows Form's code in a web page and interact with its properties and methods.

How it works?

Everything is very simple, it isn’t a “black box”. I created a Class Library project, then I added a Windows Forms UserControl and drag-and-drop'ed some components. Then I added an HTML page in the same project and I changed the code to:

   <title>My Applet</title>
   <script language=javascript>

     function Button1_onclick() {

      <OBJECT id="myID" height="150" width="300" 
    <INPUT id="Button1" type="button" value="Reset by way of javascript" 
        name="Reset" onclick="return Button1_onclick()">

On the tag OBJECT the property classid is composed by the path (I used relative path) and name of the DLL, plus namespace and class name.

Note that MyApplet (UserControl) has a button with the caption “Reset” that calls the MyMethodReset public method, setting the value of the progress bar to zero. And on the HTML file, I have another button that calls the same public method MyMethodReset by way of JavaScript!


You must create a WebSharing at the folder CSharpApplet from this source code example. Then run by, for example: http://localhost/CSharpApplet/MyApplet.htm.

Of course, .NET Framework is to be installed on clients.

Depending of what your user control will do and where it will run (by intranet/Internet), it will be necessary to trust the assembly by making proper settings on Administrative Tools > Microsoft .NET Framework Configuration/Wizards.

That’s all and sorry for my bad English!

Revision history

  • 20 February 2005

    English improvements :P


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


About the Author

Welliton Alves Toledo
Web Developer
Brazil Brazil
Welliton is a nice brazilian guy.
He started the kidding with software with his "top" PC-AT 286 in 1991 when he was 14 years old.
Now he begins solo career in a software company ( in Goiânia-Goiás - Brazil

Comments and Discussions

QuestionNot working for computers outside localhost Pin
Ivn Y.30-Jun-11 2:07
MemberIvn Y.30-Jun-11 2:07 
GeneralDrag and Drop the controls at runtime in ASP.NET application Pin
Akshay srikanth4-Aug-09 5:33
MemberAkshay srikanth4-Aug-09 5:33 
QuestionHow to access into java Web application Pin
bhangale.parag12-Jan-09 4:29
Memberbhangale.parag12-Jan-09 4:29 
QuestionHas anyone got this to work with non-.NET (ActiveX) controls? Pin
Sanx7221-Aug-08 4:47
MemberSanx7221-Aug-08 4:47 
Question.NET Applet works only on IIS? Pin
easyguy10-Jul-08 19:46
Membereasyguy10-Jul-08 19:46 
AnswerThis Code works correctly :) Pin
adel31214-Jan-08 13:09
Memberadel31214-Jan-08 13:09 
General&#304;t is not working Pin
Hakan Fatih YILDIRIM31-Oct-07 7:13
MemberHakan Fatih YILDIRIM31-Oct-07 7:13 
QuestionDoes it work on Apache ? Pin
norbp15-Jul-07 1:18
Membernorbp15-Jul-07 1:18 
QuestionInvisible applet Pin
euthebium20-Jun-07 23:41
Membereuthebium20-Jun-07 23:41 
GeneralThis example doesnt work Pin
janocho8-Feb-07 10:46
Memberjanocho8-Feb-07 10:46 
GeneralRe: This example doesnt work Pin
Welliton Alves Toledo9-Feb-07 5:43
MemberWelliton Alves Toledo9-Feb-07 5:43 
GeneralRe: This example doesnt work Pin
xilogon17-Nov-09 4:48
Memberxilogon17-Nov-09 4:48 
GeneralTrust assembly Pin
janocho7-Feb-07 14:08
Memberjanocho7-Feb-07 14:08 
GeneralRe: Trust assembly Pin
Welliton Alves Toledo9-Feb-07 5:44
MemberWelliton Alves Toledo9-Feb-07 5:44 
Generalsecutity permission Pin
rizomatosa26-Jan-07 10:18
Memberrizomatosa26-Jan-07 10:18 
GeneralRe: secutity permission Pin
Welliton Alves Toledo9-Feb-07 5:45
MemberWelliton Alves Toledo9-Feb-07 5:45 
GeneralFailed to grant minimum permission requests Pin
rictursi4-Sep-06 11:30
Memberrictursi4-Sep-06 11:30 
GeneralRe: Failed to grant minimum permission requests Pin
Welliton Alves Toledo5-Sep-06 4:27
MemberWelliton Alves Toledo5-Sep-06 4:27 
Generalbe carefull of ComVisible attribute Pin
ernest_elias29-Aug-06 4:37
Memberernest_elias29-Aug-06 4:37 
GeneralRe: be carefull of ComVisible attribute Pin
Welliton Alves Toledo5-Sep-06 4:25
MemberWelliton Alves Toledo5-Sep-06 4:25 
GeneralRe: be carefull of ComVisible attribute Pin
ProJee30-Oct-06 5:35
MemberProJee30-Oct-06 5:35 
GeneralRe: be carefull of ComVisible attribute Pin
cdmiwa13-Nov-06 10:21
Membercdmiwa13-Nov-06 10:21 
GeneralRe: be carefull of ComVisible attribute Pin
sakhawatAli6-Jan-09 2:05
MembersakhawatAli6-Jan-09 2:05 
GeneralCrashes Internet Explorer Pin
up_late6-Jun-06 16:40
Memberup_late6-Jun-06 16:40 
GeneralRe: Crashes Internet Explorer Pin
wamra15-Jun-06 7:29
Memberwamra15-Jun-06 7:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.