Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling javascript from the C# component loaded on web page

Status
Not open for further replies.

Madis

Programmer
Jan 12, 2007
3
0
0
EE
Hi!

i have web page that contains javascript and C# component. How can i call javascript function from the C# component?

C# component:

using System;
using System.Runtime.InteropServices;

namespace TerminalComm
{
[Guid("53C7EA31-BBA1-46d9-8DAE-71F374340120")]
public interface IAxTerminalComp
{
[DispId(1)] int isDeviceConnected();
}

// Events interface
[Guid("A2D7CF1D-8679-4b9a-98B4-DFAED307A886"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface AxTerminal_Events
{
}

//[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("3F576CC5-0C6E-419b-844E-BB2C541DC363"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(AxTerminal_Events))]
public class DeviceScanner : IAxTerminalComp
{
}

int isDeviceConnected()
{
}
}

and web page:

<html>
<head>
<script language="javascript">
function showMsg(msg)
{
alert(msg);
}
</script>
</head>
<body>
<H1>Test!</H1>
<object
id="test"
type="application/x-oleobject"
classid="clsid:3F576CC5-0C6E-419b-844E-BB2C541DC363"
</object>
</body>
</html>
 
Madis, Im not sure what you mean.

the C# is going to run on the server, the javascript on the client.

What are you trying to achieve?

K
 
You can call the server from JavaScript, but not the other way round, unless you classify running it in the OnLoad() event as 'calling it from the server'...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I am not sure what you r trying to do but if you want to execute a JavaScript function from the code behind what I will do is:

VS 2003/asp 1.1

Page.RegisterClientScriptBlock("key","<script>callfunction()</script");

VS 2005/asp 2.0

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"key","<script>callfunction()</script");


It means that your controls needs access to the Page where you want to call the javascrip function if you need further details let me know.
 
OK. I describe this project in more details.
Customer needs a web page that reads data from USB device and restores it to the database.
This project is divided into 2 parts: displaying and storing data in web page and ActiveX component that communicates with USB device. I'm responsible for ActiveX part and another companie developing the web page. They give me the web page with required functions to view and store date. I have to develop component that reads data from USB device and calls javascript functions to store the data. As i said before the component and javascript are in the same web page i.e. the javascript creates component object and executes it's function to read data from USB device. I used a C# to create ActiveX component.
The link i posted before describes exactly that situation: events are used to execute javascript functions.
That's it. It works now and i'm happy :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top