Library tutorials & articles

.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!

Comments

  1. 01 Feb 2007 at 14:39
    Wath about the interaction of the hosted control with the Javascript? 

    i saw that developing the control in .net 1.1 framework is it possible... but using 2.0 i got some truble...

    do you have more news?!?





  2. 02 Apr 2005 at 03:45

    Very nice and concise. Good work M!

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of .NET Applets.

Leave a comment

Sign in or Join us (it's free).

M Kenyon
AddThis

Related discussion

Related podcasts

  • More jQuery in ASP.NET

    In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, and Scott Koon conclude their discussion of Microsoft's jQuery in ASP.NET announcement1.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are ...

Events coming up

  • Nov 18

    15 Minutes of Fame

    Dresher, United States

    This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.

We'd love to hear what you think! Submit ideas or give us feedback