Click here to Skip to main content
Licence CPOL
First Posted 13 Feb 2005
Views 99,574
Downloads 682
Bookmarked 42 times

A very easy .NET “Applet”

By Welliton Alves Toledo | 13 Mar 2005
Make a Windows Forms UserControl work like an Applet.
5 votes, 29.4%
1
2 votes, 11.8%
2
1 vote, 5.9%
3
4 votes, 23.5%
4
5 votes, 29.4%
5
3.16/5 - 17 votes
μ 3.16, σa 2.96 [?]

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.2:07 30 Jun '11  
GeneralDrag and Drop the controls at runtime in ASP.NET application PinmemberAkshay srikanth5:33 4 Aug '09  
QuestionHow 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  
I'd like to embed a non-.NET control within the applet but this appears to fail.
 
I am embedding a VS 6.0 ActiveX control in the applet, which works fine outside of the browser, but doesn't work at all inside IE. I've tried a few different VS 6.0 ActiveX's (including Microsoft ones) and even built my ActiveX project using VS 2008 but I just get a red X in the browser where the control should be.
 
I'm guessing I need to tell .NET what the ActiveX object is. VS 2008 creates the interop references in the project but I wonder if these need to be registered somehow in .NET.
 
Anyone got any advice?
Question.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  
QuestionDoes 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  

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
Web02 | 2.5.120210.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