473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Call C# function from Javascript

Hello,
I know this has been answered before but I cannot seem to get this
working for the life of me... Any help/pointers would be greatly
appreciated.

I am trying to call a set of C# functions from Javascript.... For this
I created a c# class lib. and put all the functions there. The class
library itself references other c# assemblies. The library on its own
works fine...

Here are the steps that I took for this...

1. Create the class library
2. Add functions and declare them as public
3. Add references to System.Runtime.InteropServices
4. Set the "Register for Com Interop" to true in Project Configuration
Properties.
5. Generate a sname file and add it to assemblyinfo.cs
6. Generate unique GUID and declare it before the class declaration.
7. Build the solution from VS.NET
8. Run regasm from the bin/Release folder to register it. (also tried
the codebase option)
9. Add it to GAC using GACUtil
Javascript
===========
1. Attempt to call the Dll using ActiveXObject function

It gives an error "Microsft Jscript Runtime error: Automation server
can't create object" on the above line.

Here are some code samples...

c#
====
using ......
using System.Runtime.InteropServices
---- ------
---- ------

namespace test
{
[GUID("xxxxxxxxxxxxxxxxxxx")]
class test
{
-----
-----
}
}

javascript
=========
var obj = new ActiveXObject(test.test);
Nov 15 '05 #1
1 12582
Kannan,

Are you sure that the security settings allow you to create
ActiveXObjects in javascript? If you are running this from a web page, then
the security settings by default will prohibit the object from being
created.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kannan" <pv*******@yahoo.com> wrote in message
news:b4*************************@posting.google.co m...
Hello,
I know this has been answered before but I cannot seem to get this
working for the life of me... Any help/pointers would be greatly
appreciated.

I am trying to call a set of C# functions from Javascript.... For this
I created a c# class lib. and put all the functions there. The class
library itself references other c# assemblies. The library on its own
works fine...

Here are the steps that I took for this...

1. Create the class library
2. Add functions and declare them as public
3. Add references to System.Runtime.InteropServices
4. Set the "Register for Com Interop" to true in Project Configuration
Properties.
5. Generate a sname file and add it to assemblyinfo.cs
6. Generate unique GUID and declare it before the class declaration.
7. Build the solution from VS.NET
8. Run regasm from the bin/Release folder to register it. (also tried
the codebase option)
9. Add it to GAC using GACUtil
Javascript
===========
1. Attempt to call the Dll using ActiveXObject function

It gives an error "Microsft Jscript Runtime error: Automation server
can't create object" on the above line.

Here are some code samples...

c#
====
using ......
using System.Runtime.InteropServices
---- ------
---- ------

namespace test
{
[GUID("xxxxxxxxxxxxxxxxxxx")]
class test
{
-----
-----
}
}

javascript
=========
var obj = new ActiveXObject(test.test);

Nov 15 '05 #2

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

Similar topics

15
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
18
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
3
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
10
by: evicailieva | last post by:
A have a php scrip where I call a JavaScript function. I don't know why, but it doesn't work. At the beginning, when I was writing the script it was working but now it's not. I don't know wхat to do....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
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...

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.