473,624 Members | 2,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a local C# Dll from Javascript!

Hi
I want to write a simple DLL in C# that I can call from a local html
page using JavaScript. I'm looking for a very simple example!

The sort of think I'm looking for is from JS to call the DLL and it return
the date for example, or even just a string "abc".

Ideally I would like to see both the C# code and JS code!

Anyone help me!
May 6 '06 #1
6 12018
HI
I found this in another post!
http://www.codeguru.com/csharp/cshar...cle.php/c4263/

So how do I access it from JS?

Thanks
"Adrian" <Ad****@nospamh otmail.com.uk> wrote in message
news:pI******** ************@bt .com...
Hi
I want to write a simple DLL in C# that I can call from a local html
page using JavaScript. I'm looking for a very simple example!

The sort of think I'm looking for is from JS to call the DLL and it return
the date for example, or even just a string "abc".

Ideally I would like to see both the C# code and JS code!

Anyone help me!

May 6 '06 #2
Adrian wrote:
HI
I found this in another post!
http://www.codeguru.com/csharp/cshar...cle.php/c4263/

So how do I access it from JS?


First, try asking in a JScript newsgroup rather than a C++ newsgroup.

I'd suggest trying

microsoft.publi c.scripting.jsc ript

-cd
May 6 '06 #3
Isn't it funny how the JS groups say it a C# issue! and visa virsa, but
those with the comments know not the anwsers, or choose not to share!

Surly as there is detail of how to develop this in C# and referance is made
to using it from JS, its not unresonable to ask especialy as I don't know if
the C# DLL would or would not work from JS without a way of testing it and
point is to develop a C# DLL that can be called from a local HTML page in MS
IE6 running on XP...

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:uF******** ******@TK2MSFTN GP03.phx.gbl...
Adrian wrote:
HI
I found this in another post!
http://www.codeguru.com/csharp/cshar...cle.php/c4263/

So how do I access it from JS?


First, try asking in a JScript newsgroup rather than a C++ newsgroup.

I'd suggest trying

microsoft.publi c.scripting.jsc ript

-cd

May 7 '06 #4
"Adrian" <Ad****@nospamh otmail.com.uk> wrote in message
news:CP******** ************@bt .com...
Isn't it funny how the JS groups say it a C# issue! and visa virsa, but
those with the comments know not the anwsers, or choose not to share!


:-)

This is not an issue of deliberately not sharing information. It is not in
the interest of anyone from MS or any of the news group volunteers to keep
anything from you.

Rather, the pointer to another newsgroup serves to do two things. First, it
increases the likelihood that you will be put in contact with someone who
can help you. And second, it keeps the group in which the post was made "on
topic".

The fact that it often takes a knowledge of two or three technolgies to
accomplish a given task while newsgroup regulars tend to be masters of one
only further complicates matters.

That said, I have to tell you that I am not a JScript expert. But, were I
you, I would look at the JScript function ActiveXObject used like so

newObj = new ActiveXObject(s ervername.typen ame[, location])

It is described here:

http://msdn2.microsoft.com/en-US/library/6958xykx.aspx

That function allows you to create a COM object in script code.

Then what you need to do is to figure out how to make your C# class appear
to clients as a COM object. One way to do that is to use the RegAsm
(register assembly) tool to register a .Net assembly as a COM object. It is
described here:

http://msdn.microsoft.com/library/de...lRegasmexe.asp

Now, I'm neither an expert at scripting or COM - you'll find one of those
characters in another group. There may be other hurdles involved (security?)
in the solution I sketched and in fact there may be a better method. Good
luck.

Regards,
Will
May 7 '06 #5
Adrian wrote:
Isn't it funny how the JS groups say it a C# issue! and visa virsa,


No doubt, but this is a C++ newsgroup, not C# nor JScript.

You need to expose your C# class as a COM callable object. See the
COMVisibleAttri bute in the .NET documentation.

You need to regisster your C# DLL as a COM server - see regasm.exe in the
..NET framework SDK (you should already have it if you have a C# compiler).

If you're going to access your C# COM DLL from a web page (i.e. ASP), you'll
need to strong-name your assembly (see sn.exe in the .NET framework) and put
it in the GAC (see gacutil.exe in the .NET framework).

This article

http://www.codeproject.com/dotnet/cominterop.asp

contains a lot of information on COM/.NET interop, which is what you need to
understand to mix JScript and C#.

-cd
May 7 '06 #6
Hi
Thanks you both for your reply Sorry I have on just started looking at C#
and only done vb and vb.net till now! VC was C# opps!!!

Lots of good info I will red through thangs Carl.

I have also just found this
http://www.devhood.com/tutorials/tut...utorial_id=187

It seems to be exactly what I'm looking for...

Thanks

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:el******** ******@TK2MSFTN GP03.phx.gbl...
Adrian wrote:
Isn't it funny how the JS groups say it a C# issue! and visa virsa,
No doubt, but this is a C++ newsgroup, not C# nor JScript.

You need to expose your C# class as a COM callable object. See the
COMVisibleAttri bute in the .NET documentation.

You need to regisster your C# DLL as a COM server - see regasm.exe in the
.NET framework SDK (you should already have it if you have a C# compiler).

If you're going to access your C# COM DLL from a web page (i.e. ASP),

you'll need to strong-name your assembly (see sn.exe in the .NET framework) and put it in the GAC (see gacutil.exe in the .NET framework).

This article

http://www.codeproject.com/dotnet/cominterop.asp

contains a lot of information on COM/.NET interop, which is what you need to understand to mix JScript and C#.

-cd

May 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
25845
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the function...if that makes sense. Here's what I mean... I have a javascript array set up like so: <script language="javascript" TYPE="text/JavaScript"> //custom object constructor
3
3106
by: MicroMoth | last post by:
Hi, I'm trying to call a Javascript function within a foreach loop. I am loop over a series of users and I want to call the JS function which opens a new window, passing in the user id to each call for the JS function. So far I've done this: foreach (USER _user in users) { string jscriptString = "<script language='JavaScript'>";
13
18676
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
3
1497
by: fluxent | last post by:
(Environment: RedHat Linux recent, Python 2.3.5) We have a batch processing script that on occasion needs to send out an email. We have a sendmail running locally. Sometimes we get a socket timeout on sending that email. Increasing the timeout to 30sec reduced but did not eliminate it. It seems to happen more often when sending to some addresses in the UK, but it's definitely not limited to that.
5
3241
by: Newbie Coder | last post by:
Hello all I have 3 functions in a javacrip file (MyScript.js), which is added to an ASP.NET 2.0 project 1) no right-click 2) no select text (copy...) 3) History.Back()' How do I call those 3 functions in all of my pages?
6
10618
by: Ajit Goel | last post by:
Hi; We have a Javascript function which I have been tasked to move to a CSharp class. This javascript function uses Regular expression extensively. This function has a string input parameter and output parameter. My questions are: a. Can I expose a function in my CSharp code and internally call a javascript function?? Is this a good idea?? b. Do we have any tool which can convert a javascript function into
1
1669
by: susmitha | last post by:
hai iam a fresher in .net.My problem is I have one javascript sourcefile and some javascript functions in my aspx page like shown below. <script language=javascript src="javascripts/popcalendar.js" type="text/javascript"/> <script language="javascript" type="text/javascript"> function callpopup(v1,v2,v3,v4) { var txtName =document.getElementById(v1).value; var txtSal = document.getElementById(v2).value; ...
2
7656
by: moni | last post by:
Hi, I wanted to call a javascript function function showAddress(address) { ..... } from the aspx.cs file from the Gridview_RowCommand function
15
4266
by: Sampat | last post by:
Hi, I wanted to know the performance of calling a function pointer v/s a normal function call in javascript in a scenario where there are multiple calls in the js to the same function. Please share your thoughts if someone has worked on this. Thanks, Sampat.
2
2215
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the pages that used Tab controls. Because it was generated in this way I was able to specify which tab was to be displayed as the "current" tab upon rendering the page in the browser. Since the JavaScript is now a fixed resource that resides on the...
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.