?
Solved

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

Posted on 2010-01-12
13
Medium Priority
?
1,012 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
13 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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