.NET Applets

The HTML Code

For simplicity's sake, create a Web Project. In your default page put a tag like this:

<object id='ControlID' classID='PathToAssemblyFile.dll#Qualified.Class.Name' />

Place the complied DLL from your control project in the same virtual directory as the HTML. Then browse to it. Your control should pop up. As you select the items, the label should change. You have just created a .NET Applet. (Note: If you run this from the local machine or an Intranet Webserver you will not be as restricted as a control run from the Internet zone. Keep this in mind when your users say it's not working out of the office.) Here's an example of the html:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="demoPage.aspx.vb" Inherits="demoWebProj.demoPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <title>Cropping an Image</title>
</HEAD>
<body id="bdyElem" runat="server">
  <form id="Form1" runat="server">
  <OBJECT id="myControl" height="620" width="500" classid="PathToAssemblyFile.dll#Qualified.Class.Name'
    viewastext>
    <PARAM NAME="value1" VALUE="<%# dynamicValue %>">
    <PARAM NAME="value2" VALUE="thisIsStatic">
  </OBJECT>
  </form>
  </body>
</HTML>

Debugging

Okay, so you wire up your code, place your <Object> tag, and load up the page. Nothing. No error, nothing. You're not going to get a message (unless you dump exception strings to a label in your control). And even if you did, you start debugging aspnet_wp.exe, set some break points in your new control, and still nothing!

Here's the trick (sorry if you're not using Visual Studio): click Tools | Debug Processes, and scroll through the list of processes. Spot the IExplorer with your web page in it, and notice under the 'Types' field. See the .NET there? That's your component! Attach to that, and you will now be able to debug your .NET Applet. Pretty cool, huh!

Parameters

What! This isn't enough? You want to pass parameters to your control? You don't know how to do this? Neither did I. I never really used the Object tag much. But now I am, and passing parameters is easy.

Between your opening and closing <Object> tags place a <Param> tag. Here's an example:

<param name="publicProp" value='yadaYadaYada' />

Not to bad. How about dynamic or programmatic values? Try this:

<param name="publicProp" value='<%# myYadaValue %>' />

'myYadaValue' is a public property in your web pages code. Easy, right? Now how about values in your Applet, how do you get these? You need to create a public property. You cannot pass to a public variable, be-it string, integer, boolean, or what-not. Has to be a property. So do up your code for a property and you can now access it with Javascript.

HTH

Props to Sven Groot on Channel 9 and Ben the Developer for all the help, thanks!

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann