Click here to Skip to main content
Licence CPOL
First Posted 13 Feb 2005
Views 101,924
Bookmarked 42 times

A very easy .NET “Applet”

By | 13 Mar 2005 | Article
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)

About the Author

Welliton Alves Toledo

Web Developer

Brazil Brazil

Member

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNot working for computers outside localhost PinmemberIvn Y.1:07 30 Jun '11  
GeneralDrag and Drop the controls at runtime in ASP.NET application PinmemberAkshay srikanth4:33 4 Aug '09  
QuestionHow to access into java Web application Pinmemberbhangale.parag3:29 12 Jan '09  
QuestionHas anyone got this to work with non-.NET (ActiveX) controls? PinmemberSanx723:47 21 Aug '08  
Question.NET Applet works only on IIS? Pinmembereasyguy18:46 10 Jul '08  
AnswerThis Code works correctly :) Pinmemberadel31212:09 14 Jan '08  
Generalİt is not working PinmemberHakan Fatih YILDIRIM6:13 31 Oct '07  
İ downloaded the sample and execute the html file but it is not working. i can't see the applet.
QuestionDoes it work on Apache ? Pinmembernorbp0:18 15 Jul '07  
QuestionInvisible applet Pinmembereuthebium22:41 20 Jun '07  
GeneralThis example doesnt work Pinmemberjanocho9:46 8 Feb '07  
GeneralRe: This example doesnt work PinmemberWelliton Alves Toledo4:43 9 Feb '07  
GeneralRe: This example doesnt work Pinmemberxilogon3:48 17 Nov '09  
GeneralTrust assembly Pinmemberjanocho13:08 7 Feb '07  
GeneralRe: Trust assembly PinmemberWelliton Alves Toledo4:44 9 Feb '07  
Generalsecutity permission Pinmemberrizomatosa9:18 26 Jan '07  
GeneralRe: secutity permission PinmemberWelliton Alves Toledo4:45 9 Feb '07  
GeneralFailed to grant minimum permission requests Pinmemberrictursi10:30 4 Sep '06  
GeneralRe: Failed to grant minimum permission requests PinmemberWelliton Alves Toledo3:27 5 Sep '06  
Generalbe carefull of ComVisible attribute Pinmemberernest_elias3:37 29 Aug '06  
GeneralRe: be carefull of ComVisible attribute PinmemberWelliton Alves Toledo3:25 5 Sep '06  
GeneralRe: be carefull of ComVisible attribute PinmemberProJee4:35 30 Oct '06  
GeneralRe: be carefull of ComVisible attribute Pinmembercdmiwa9:21 13 Nov '06  
GeneralRe: be carefull of ComVisible attribute PinmembersakhawatAli1:05 6 Jan '09  
GeneralCrashes Internet Explorer Pinmemberup_late15:40 6 Jun '06  
GeneralRe: Crashes Internet Explorer Pinmemberwamra6:29 15 Jun '06  

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.

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