Running Client Side C# Using ASP.NET

S

steve_barker333

Hi guys!

I found a great article a while ago about how to write client side C#.
Sadly, I can't find it again now, but here's the jist of what I learnt
to do:

1. Write a C# (or any .NET language) dll.
2. Write a web page in ASP.NET.
3. Put the dll from 1 into the virtual directory that 2 lives in (the
root).
4. Use an object tag in the web page to download the dll onto the
client machine when the page loads.
5. Fire some javascript from within the web page to access methods in
the dll client side, effectively running code from 1 on the client,
with no need for post backs etc...

This sounds too good to be true, right? It really does work! There is
an obvious draw back: The client needs to have the .NET framework
installed! This is obviously a problem if you want to expose your
functionality across the whole of the web, but for a controlled area,
such as a company network, this method can be a great way to deploy
enhanced web applications. There's no installation needed (apart from
the framework), and if the dll mentioned in 1 is updated, the web page
automatically downloads the new version of the component. I have put
this technology to great use within my company: I have written a web
page that provides spell checking on text fields. Clearly, I don't want
to send the page back to the server every time I want to check the
spelling, so I have written a .NET dll that launches a contained form.
Text from a HTML text box is passed to the form, which checks the
spelling against a dictionary file embedded in my .NET dll. When the
form (which is displayed as modal from IE) closes, the corrected text
is put back into the HTML text box. Everything works dynamically.

Here are some technical details:

The object tag mentioned in 4 looks like this:

<OBJECT id="textEditor"
classid="http:ClientSideCode.dll#ClientSideCode.TextEditor" name="Text"
VIEWASTEXT></OBJECT>

Note that the classid is made up as follows: "http:{DLL File
Name}#{Default DLL namespace}.{Class name}

The javascript function would then look like this:

function EditText()
{
alert(textEditor.EditText(document.Form1.txtText.value);
}

....assuming a control called txtText exists. Of course, the result from
this call need not be put into a message. You can do anything with the
return value, and pass a string from any source.

The method that got called in the C# dll would look something like
this:

public string EditText(string Text)
{
//Implementation
return Text;
}

However, and here is the but.... I've had this method working fine on a
whole host of machines, but every now and then I find a machine that
simply refuses to allow this method to work, even though the EXACT SAME
code works fine on other machines.

This is the message I get:

Error: Object doesn't support this property or method

I figure there must be a setting I need to tweak on these machines to
make it work, but I have no idea what I'm looking for. Can anyone
help!? I'm all out of ideas!

Thanks in advance for your help!

Steve.
 
E

Eric David

Steve,
Kudos on the post! I think I know the article you're talking about...
but I could be wrong. Is it this one?
http://msdn.microsoft.com/msdnmag/issues/02/06/rich/default.aspx
Also, the xml programming for .net book by Dino Esposito has an example
of using a dll from Winforms on the client. I've had a similar problem
to yours... but at a much simpler level. The code that is in the first
article runs just fine when I run it from localhost/code, but if I try
to execute the same page but by using mydomain/code it throws the same
error as the one you're getting. My guess is that it could have
something to do with security zones... and there's also sometimes (i
humbly offer) a disconnect between the control and the javascript
calling it... But if I find anything meaningful out I'll be sure to
post it here. Hope that helps...

E
 
S

steve_barker333

Eric,

Thanks for your reply Eric, and for your kind words! The link you have
included isn't the one I was thinking about, but it is similar. I've
had the code in my example running from server to client on a LAN,
using http:\\{IP}\etc... addresses and http:\\{server name}\etc... It
seems random as to which machines it will and won't work on at the
moment! I've even had problems running the code on a single machine
acting as both client and server, which is strange. Do you think it is
due to restrictions imposed by IIS, IE, ASP.NET, .NET Framework or the
machine itself? (That's a lot of choices!)

I suspect that my problems are security related as well; no doubt it'll
turn out to be a check box buried 10 menus deep that is missing a
check! If anyone can locate this check box (or whatever it is!) I'd be
very interested to hear what I need to do!

Cheers,

Steve.
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

Did you make sure that the permissions were granted for the assembly you
are loading from the site? You have to go into the .NET Framework
Administration for the version of .NET you are running, and make sure that
the assembly that you are loading has the appropriate permissions.

Hope this helps.
 
S

steve_barker333

Nicholas,

Thanks for the advice! However, could you be a bit more specific about
which settings I need to change please? I've had a look through the
..NET Configuration security settings, and there are a lot of options to
play with!

Steve.
 
S

steve_barker333

Nicholas,

I don't know if you saw my last message, but I still can't get this
thing working on my machine at home! Could you suggest which settings I
look at changing please. Are we talking IIS, .NET Framework or
something else?!

Thanks a lot!

Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top