Click here to Skip to main content
6,630,586 members and growing! (18,352 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » Samples     Intermediate License: The Code Project Open License (CPOL)

A very easy .NET “Applet”

By Welliton Alves Toledo

Make a Windows Forms UserControl work like an Applet.
C#, HTML, Windows, .NET 1.1VS.NET2003, Dev
Posted:13 Feb 2005
Updated:13 Mar 2005
Views:77,357
Bookmarked:38 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 3.77 Rating: 3.13 out of 5
5 votes, 31.3%
1
2 votes, 12.5%
2
1 vote, 6.3%
3
3 votes, 18.8%
4
5 votes, 31.3%
5

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


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
Occupation: Web Developer
Location: Brazil Brazil

Other popular .NET Framework articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 55 (Total in Forum: 55) (Refresh)FirstPrevNext
GeneralDrag and Drop the controls at runtime in ASP.NET application PinmemberAkshay srikanth5:33 4 Aug '09  
GeneralHow to access into java Web application Pinmemberbhangale.parag4:29 12 Jan '09  
QuestionHas anyone got this to work with non-.NET (ActiveX) controls? PinmemberSanx724:47 21 Aug '08  
General.NET Applet works only on IIS? Pinmembereasyguy19:46 10 Jul '08  
AnswerThis Code works correctly :) Pinmemberadel31213:09 14 Jan '08  
Generalİt is not working PinmemberHakan Fatih YILDIRIM7:13 31 Oct '07  
GeneralDoes it work on Apache ? Pinmembernorbp1:18 15 Jul '07  
QuestionInvisible applet Pinmembereuthebium23:41 20 Jun '07  
GeneralThis example doesnt work Pinmemberjanocho10:46 8 Feb '07  
GeneralRe: This example doesnt work PinmemberWelliton Alves Toledo5:43 9 Feb '07  
GeneralRe: This example doesnt work Pinmemberxilogon4:48 17 Nov '09  
GeneralTrust assembly Pinmemberjanocho14:08 7 Feb '07  
GeneralRe: Trust assembly PinmemberWelliton Alves Toledo5:44 9 Feb '07  
Generalsecutity permission Pinmemberrizomatosa10:18 26 Jan '07  
GeneralRe: secutity permission PinmemberWelliton Alves Toledo5:45 9 Feb '07  
GeneralFailed to grant minimum permission requests Pinmemberrictursi11:30 4 Sep '06  
GeneralRe: Failed to grant minimum permission requests PinmemberWelliton Alves Toledo4:27 5 Sep '06  
Generalbe carefull of ComVisible attribute Pinmemberernest_elias4:37 29 Aug '06  
GeneralRe: be carefull of ComVisible attribute PinmemberWelliton Alves Toledo4:25 5 Sep '06  
GeneralRe: be carefull of ComVisible attribute PinmemberProJee5:35 30 Oct '06  
GeneralRe: be carefull of ComVisible attribute Pinmembercdmiwa10:21 13 Nov '06  
GeneralRe: be carefull of ComVisible attribute PinmembersakhawatAli2:05 6 Jan '09  
GeneralCrashes Internet Explorer Pinmemberup_late16:40 6 Jun '06  
GeneralRe: Crashes Internet Explorer Pinmemberwamra7:29 15 Jun '06  
GeneralRe: Crashes Internet Explorer Pinmemberwamra7:34 15 Jun '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Mar 2005
Editor: Sumalatha K.R.
Copyright 2005 by Welliton Alves Toledo
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project