Click here to Skip to main content
Click here to Skip to main content

A very easy .NET “Applet”

, 13 Mar 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
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>
   <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)

Share

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

Comments and Discussions

 
QuestionNot working for computers outside localhost PinmemberIvn Y.30-Jun-11 2:07 
GeneralDrag and Drop the controls at runtime in ASP.NET application PinmemberAkshay srikanth4-Aug-09 5:33 
QuestionHow to access into java Web application Pinmemberbhangale.parag12-Jan-09 4:29 
QuestionHas anyone got this to work with non-.NET (ActiveX) controls? PinmemberSanx7221-Aug-08 4:47 
Question.NET Applet works only on IIS? Pinmembereasyguy10-Jul-08 19:46 
AnswerThis Code works correctly :) Pinmemberadel31214-Jan-08 13:09 
General&#304;t is not working PinmemberHakan Fatih YILDIRIM31-Oct-07 7:13 
QuestionDoes it work on Apache ? Pinmembernorbp15-Jul-07 1:18 
QuestionInvisible applet Pinmembereuthebium20-Jun-07 23:41 
GeneralThis example doesnt work Pinmemberjanocho8-Feb-07 10:46 
GeneralRe: This example doesnt work PinmemberWelliton Alves Toledo9-Feb-07 5:43 
GeneralRe: This example doesnt work Pinmemberxilogon17-Nov-09 4:48 
GeneralTrust assembly Pinmemberjanocho7-Feb-07 14:08 
GeneralRe: Trust assembly PinmemberWelliton Alves Toledo9-Feb-07 5:44 
Generalsecutity permission Pinmemberrizomatosa26-Jan-07 10:18 
GeneralRe: secutity permission PinmemberWelliton Alves Toledo9-Feb-07 5:45 
GeneralFailed to grant minimum permission requests Pinmemberrictursi4-Sep-06 11:30 
GeneralRe: Failed to grant minimum permission requests PinmemberWelliton Alves Toledo5-Sep-06 4:27 
Generalbe carefull of ComVisible attribute Pinmemberernest_elias29-Aug-06 4:37 
GeneralRe: be carefull of ComVisible attribute PinmemberWelliton Alves Toledo5-Sep-06 4:25 
GeneralRe: be carefull of ComVisible attribute PinmemberProJee30-Oct-06 5:35 
GeneralRe: be carefull of ComVisible attribute Pinmembercdmiwa13-Nov-06 10:21 
GeneralRe: be carefull of ComVisible attribute PinmembersakhawatAli6-Jan-09 2:05 
GeneralCrashes Internet Explorer Pinmemberup_late6-Jun-06 16:40 
GeneralRe: Crashes Internet Explorer Pinmemberwamra15-Jun-06 7:29 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 14 Mar 2005
Article Copyright 2005 by Welliton Alves Toledo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid