Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to call OCX functions from .js in C# .net code behind

Posted on 2010-01-12
13
Medium Priority
?
1,027 Views
Last Modified: 2013-12-17
Hi experts,
I'm not really sure if my question is going to be right, but here it goes.
I have a vb6 OCX that works with maps.
It has some functions that returns values like geocoding, reverse geocoding, driving directions, etc
For example, there is a function to add a point to the built map:

map.AgregarPunto(double latitude, double longitude, int point_id)

It works in a Win Form app, but I cannot make it work in a web page, because I think that the OCX is not designed for web.
I managed to call some functions in javascript -previously added the map with <OBJECT>- but I need to make it work from C# code behind.
Is there a way to do that?

Any help will be really appreciated.
Thanks in advance.
Regards,

Leandro Nuñez.
0
Comment
Question by:Leandronn
  • 5
  • 3
9 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 26323161
Have you added the ocx and instanciated it?

Are you getting any exceptions?
0
 
LVL 2

Author Comment

by:Leandronn
ID: 26328586
Dear MogalManic:

It's instanced as INTEROP.ocxname.DLL
There are no exceptions, I'm able to retrieve the map, but I need to figure out a way to call the .js functions from my code behind... Something like the example I'll attach as code.

Thanks in advance for your answer.
/////////////////THIS IS WHAT I COULD DO/////////////////////////
//javascript

function AgregarPunto(){
    var mapa = document.GetElementByID("axMapa");
    mapa.AgregarPunto(-34.554433,-58.554322);
    mapa.Actualizar();
}

//aspx
<input id="btn2" type="button" value="punto" onclick="AgregarPunto()" />


/////////////////THIS IS WHAT I NEED TO DO/////////////////////////


//cybMap.ascx user control 

<object id="axMapa"/>

//aspx

<%@ Register Src="~/cybMap.ascx" TagName="cybMap" TagPrefix="cybMap" %>
<cybMap:cybMap id="mapa" runat="server />
<asp:button id="btnAgregarPunto" runat="server" onClick="btnAgregarPunto" />

//code behind

public void btnAgregarPunto(object sender, EventArgs e)
{
    double latitud = -34.4443333;
    double longitud = -58.45533332;
    this.mapa.AgregarPunto(latitud, longitud);
    this.mapa.Actualizar();
}

Open in new window

0
 
LVL 8

Expert Comment

by:PeteEngineer
ID: 26330015
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Leandronn
ID: 26331057
PeteEngineer:
My basic problem, is that I'm not a genius in javascript programming, and I don't have the time to make my OCX working with javascript (which I know it works great)

I've found a solution that uses google maps api, to build maps using a webservice, and everything is called from the code behind (http://www.c-sharpcorner.com/UploadFile/shabdarghata/google-maps-user-control-for-ASP-Net-part103232008234414PM/google-maps-user-control-for-ASP-Net-part1.aspx) but every function is written in javascript.

Hope you understand my question.


Regards,

Leandro Nuñez.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 26340091
You cannot call the JavaScript from the codebehind.  The Javascript resides in the browser and the CodeBehind is on the server.  So if you are registering the OCX on the server, it won't exist on the client (and vice versa)
0
 
LVL 2

Author Comment

by:Leandronn
ID: 26346286
MogalManic:
I think that the differences between server and client should be discarded... I already know them...
So? How should OCX functions from the server?

Thanks anyways for your answer.
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 1500 total points
ID: 26348984
They should function from the server.  There are two forms of OCX.  Most of them render them-selfs to a form and require GDI functionality.

How are you registering the DLL.  You should be able to just create a new instance of the object.  So if the registered object is INTEROP.ocxname you should be able to create a new instance like this:
  INTEROP.ocxname OcxObject=new INTEROP.ocxname();
   object result=OcxObject.ObjectMethod(param1);

If the function returns a result you can then send it pack to the page.




0
 
LVL 2

Author Comment

by:Leandronn
ID: 26359566
Dear MogalManic:
It was a great answer!, I finally could call my functions from the code behind.
There is just one issue to resolve in this case now:

How do I relate my <OBJECT ID="axMapa"> to the NEW OBJECT in my codebehind?

Hope you understand my question.

Thanks in advance.

Regards,

LEandro Nuñez.
0
 
LVL 2

Author Closing Comment

by:Leandronn
ID: 31676457
There are some things missing to complete my question
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question