473,804 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("xxxxxxxxx xxxxxxxxxx")]
class test
{
-----
-----
}
}

javascript
=========
var obj = new ActiveXObject(t est.test);
Nov 15 '05 #1
1 12606
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.co m

"Kannan" <pv*******@yaho o.com> wrote in message
news:b4******** *************** **@posting.goog le.com...
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("xxxxxxxxx xxxxxxxxxx")]
class test
{
-----
-----
}
}

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

Nov 15 '05 #2

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

Similar topics

15
4217
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 the function as:
5
2694
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 function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
1
5080
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 they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf) System.Web.HttpContext.Current.Response.Write("if (confirm('Are you sure you want to...
3
4064
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: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the onChange() or Click() does not do anything. It only seems to fire the onchange if I
39
6570
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. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
18
43571
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. (It's for Google Maps, but I won't bore you with the complexities of that, as it doesn't affect the question). Mochas kudos to anyone able to solve this widdle.
3
3598
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 a javascript method. I try it with GetCallbackEventReference but this tech works async. Could I use a javascript function with a sync call ? Thaks for responses,
3
3689
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 html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
10
7305
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. Please help me. Here is the php code: function print_rezBilet($rezBilet,$posRezBilet1){ $step=$_SESSION; $max=$_SESSION; $curr= $_SESSION+$step-1 ; if($max<$curr) $curr=$max;
0
9593
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
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7633
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
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4306
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
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.