Click here to Skip to main content
Email Password   helpLost your password?

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralDrag and Drop the controls at runtime in ASP.NET application
Akshay srikanth
5:33 4 Aug '09  
Can anyone help
I want to create an application that has a toolbox at runtime, drag the controls from toolbox and drop in the form. Once we drop the controls in the form, the properties related to that particular control should be displayed in property Panel. Once we change the properties it should affect the form controls.
(This Application like Visual studio toolbox and property box)
GeneralHow to access into java Web application
bhangale.parag
4:29 12 Jan '09  
hi ,
how can access this control in my java web application i.e. on jsp the dll is not loaded i try that please reply me..........
QuestionHas anyone got this to work with non-.NET (ActiveX) controls?
Sanx72
4: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?
General.NET Applet works only on IIS?
easyguy
19:46 10 Jul '08  
Hi,

I don't know why but the same .NET applet works when hosted on IIS but fails when hosted on other web server.

Any idea?

cheers
AnswerThis Code works correctly :)
adel312
13:09 14 Jan '08  
This code works correctly, simply you need to install the server IIS and run the html file from there example:

http://localhost/CSharpApplet/myapplet.htm Poke tongue

It Not work if you are running either locally
Like this:

C:\CSharpApplet\myapplet.htm Mad
Generalİt is not working
Hakan Fatih YILDIRIM
7:13 31 Oct '07  
İ downloaded the sample and execute the html file but it is not working. i can't see the applet.
GeneralDoes it work on Apache ?
norbp
1:18 15 Jul '07  
Hello

Does it work on Apache ?
QuestionInvisible applet
euthebium
23:41 20 Jun '07  
Hello...
I made an applet just like you did but when I run the webapplication the applet is invisible.
I get a little square(10x10).
I've signed the assembly with a strong name but I still can't see the applet.
Some time ago I've made it work but I after I've uninstall the framework and install it again the applet was invisible.
And another thing: when the applet was working on my machine, it was invisible on other machines from my intranet.
What should I do to make it work on both my machine and other machines?
Thanks
GeneralThis example doesnt work
janocho
10:46 8 Feb '07  
I tried to use the example but it doesnt run, my IE only diplays something that looks like a text area, but not what it should display, please tell me how to make it work, i'm desperate!
GeneralRe: This example doesnt work
Welliton Alves Toledo
5:43 9 Feb '07  
try check the relative path of the dll:

In this example it is in "bin/release" sub-folder:

<OBJECT id="myID" height="150" width="300"
classid="http:bin/release/CSharpApplet.dll#CSharpApplet.MyApplet"
VIEWASTEXT...



www.iconnect.com.br

GeneralRe: This example doesnt work
xilogon
4:48 17 Nov '09  
Sleepy
This example doesn't work!!! D'Oh! D'Oh! D'Oh!
Please help!!
GeneralTrust assembly
janocho
14:08 7 Feb '07  
Hi can you please tell me which assembly do I have to choose to make this example work? I really need that info.
GeneralRe: Trust assembly
Welliton Alves Toledo
5:44 9 Feb '07  
CSharpApplet.dll

hth

Welliton Alves Toledo
www.iconnect.com.br

Generalsecutity permission
rizomatosa
10:18 26 Jan '07  
i've added a button to read and write a file on client but the applet does not work for a denied access. Java applet for such task have to be sign ( so the web browser asks if you want download a page so signed) , but i don't know what i've to do for the c# applet. any suggestion?
GeneralRe: secutity permission
Welliton Alves Toledo
5:45 9 Feb '07  
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.
Hth

Welliton Alves Toledo
www.iconnect.com.br

GeneralFailed to grant minimum permission requests
rictursi
11:30 4 Sep '06  
I have created an ActiveX control that works well when inserted in a Windows Application.

I have tried to put it in an HTML page, but it doesn't load.
This is the message of the error:
Could not load file or assembly 'csgl, version 1.4.1.0, Culure=neutral, PublicKeyToken=d9fb3bdb88c36cd4' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)

My ActiveX control has another one inside it, used for showing graphics using openGL (using the wrapper library CsGL). It's a permissions problem of this library? How can I fix it? I repeat it works fine in a windows application..

More't

GeneralRe: Failed to grant minimum permission requests
Welliton Alves Toledo
4:27 5 Sep '06  
Maybe granting permissions on IE settings?

Welliton Alves Toledo
www.iconnect.com.br

Generalbe carefull of ComVisible attribute
ernest_elias
4:37 29 Aug '06  
I created my own testing library in VS.NET 2005 with HelloWorld User Control. The control displays string "Say Hello" and it has public method Hello().
The control was displayed correctly, but IE was unable to call the method through Javascript.
I had to do long-time exploration and I found that VS.NET 2005 creates attribute [assembly: ComVisible(false)] in AssemblyInfo.cs (by default), which makes the method invisible to IE.
I solved the problem due to your sample project Smile
Thank you

-ernest

GeneralRe: be carefull of ComVisible attribute
Welliton Alves Toledo
4:25 5 Sep '06  
No worry, later you pay to me a Big Mac!

Smile

Welliton Alves Toledo
www.iconnect.com.br

GeneralRe: be carefull of ComVisible attribute
ProJee
5:35 30 Oct '06  
I've spent 5 hours searching. Rose
GeneralRe: be carefull of ComVisible attribute
cdmiwa
10:21 13 Nov '06  
FWIW: In VS2005, this attribute can be accessed via Project Properties, Application Tab, Assembly Information, "Make Assembly COM Visible".


GeneralRe: be carefull of ComVisible attribute
sakhawatAli
2:05 6 Jan '09  
Thanks. I was having the same problem. ComVisible works.
GeneralCrashes Internet Explorer
up_late
16:40 6 Jun '06  
If I put two of these objects on the same page, then Internet Explorer crashes as soon as it attempts to render the second one. I see the first one get rendered, then the background for the second paints, then IE silently exits. Is anybody else seeing this? Any ideas on a work-around?

GeneralRe: Crashes Internet Explorer
wamra
7:29 15 Jun '06  
Yes I've seen the same thing after I had .NET 2.0 installedMad
GeneralRe: Crashes Internet Explorer
wamra
7:34 15 Jun '06  
try adding a dropdown html box ... <select> its crashing IE when I combine a .NET Applet and drop down.




Last Updated 14 Mar 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010