Click here to Skip to main content
15,891,136 members
Articles / Web Development / HTML
Article

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 171.4K   1.7K   46   56
Make a Windows Forms UserControl work like an Applet.

Sample Image - CSharpApplet.gif

Introduction

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:

HTML
<html>
   <head>
   <title>My Applet</title>
   <script language=javascript>
   <!--

     function Button1_onclick() {
        document.getElementById("myID").MyMethodReset();
    }

   //-->
  </script>
  </head>
  <body>
      <OBJECT id="myID" height="150" width="300" 
        classid="http:bin/release/CSharpApplet.dll#CSharpApplet.MyApplet"
        VIEWASTEXT>
     </OBJECT>
    <P>
    <INPUT id="Button1" type="button" value="Reset by way of javascript" 
        name="Reset" onclick="return Button1_onclick()">
  </body>
</html>

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!

Remarks

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

License

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


Written By
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 (http://www.actuar.com.br) in Goiânia-Goiás - Brazil

Comments and Discussions

 
GeneralWebSharing Pin
Patrice Dargenton2-Apr-05 21:34
Patrice Dargenton2-Apr-05 21:34 
GeneralRe: WebSharing Pin
Welliton Alves Toledo3-Apr-05 15:00
Welliton Alves Toledo3-Apr-05 15:00 
GeneralRe: WebSharing Pin
Patrice Dargenton4-Apr-05 4:54
Patrice Dargenton4-Apr-05 4:54 
GeneralQuestion Pin
Sk8tz27-Feb-05 17:59
professionalSk8tz27-Feb-05 17:59 
GeneralRe: Question Pin
Welliton Alves Toledo2-Mar-05 13:40
Welliton Alves Toledo2-Mar-05 13:40 
GeneralRe: Question Pin
Sk8tz4-Mar-05 1:19
professionalSk8tz4-Mar-05 1:19 
GeneralRe: Question Pin
Welliton Alves Toledo11-Mar-05 16:17
Welliton Alves Toledo11-Mar-05 16:17 
GeneralRe: Question Pin
Sk8tz13-Mar-05 18:11
professionalSk8tz13-Mar-05 18:11 
Questions

1) Doing it this way, is the exe running from the client or server, cause theres always the case of authentication.
2) If running on the client will it download the exe all the time when it runs, or only first time and thereafter when there is any new updates on the site.
3) Will remoting then solve serialization of information from the smart client (aspx) to the exe(winform).
4) Is there any way of creating a ocx in .NET


:->


Sk8tZ
GeneralRe: Question Pin
Welliton Alves Toledo13-Mar-05 18:25
Welliton Alves Toledo13-Mar-05 18:25 
Generalawsome !!! Pin
DaberElay20-Feb-05 10:23
DaberElay20-Feb-05 10:23 
GeneralRe: awsome !!! Pin
Welliton Alves Toledo21-Feb-05 9:16
Welliton Alves Toledo21-Feb-05 9:16 
GeneralRe: awsome !!! Pin
wamra15-Jun-06 6:32
wamra15-Jun-06 6:32 
GeneralRe: awsome !!! Pin
DaberElay15-Jun-06 22:25
DaberElay15-Jun-06 22:25 
GeneralFirefox Pin
Klapouchy13-Feb-05 23:02
Klapouchy13-Feb-05 23:02 
GeneralRe: Firefox Pin
Welliton Alves Toledo14-Feb-05 1:03
Welliton Alves Toledo14-Feb-05 1:03 
GeneralRe: Firefox Pin
Klapouchy14-Feb-05 1:12
Klapouchy14-Feb-05 1:12 
GeneralRe: Firefox Pin
jake h14-Feb-05 7:09
jake h14-Feb-05 7:09 
GeneralRe: Firefox Pin
Welliton Alves Toledo14-Feb-05 15:35
Welliton Alves Toledo14-Feb-05 15:35 
GeneralRe: Firefox Pin
Anonymous23-Feb-05 3:43
Anonymous23-Feb-05 3:43 
GeneralRe: Firefox Pin
Welliton Alves Toledo23-Feb-05 8:53
Welliton Alves Toledo23-Feb-05 8:53 
GeneralRe: Firefox Pin
The_Decryptor14-Mar-05 1:49
The_Decryptor14-Mar-05 1:49 
GeneralRe: Firefox Pin
Judah Gabriel Himango21-Feb-05 8:12
sponsorJudah Gabriel Himango21-Feb-05 8:12 

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.