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