ASP或ASPX不支持ActiveX组件的JavaScript通过引用传递 [英] JavaScript Pass by Reference for ActiveX Component not supported in ASP or ASPX

查看:117
本文介绍了ASP或ASPX不支持ActiveX组件的JavaScript通过引用传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

We  are working on some migration project for moving from classic ASP to ASPX. Currently we are stucked in one task  of this project which include  moving the .vbs code to .js

The .vbs code  contains some COM component call  which set the value in some output variable (pointer/reference variable) and that value is accessible within the vbs code after calling the COM

The .vbs call  the COM component Validate() method in Validation.dll as below and the foobar variable is accessible
.VBS Code :
Function genValidationResponse(req)
    Dim valob
    Dim retval, foobar
    Set valob = CreateObject("Validation.Validator")
    retval = valob.Validate(req, foobar)
End Function

COM CODE :  Validate method Signature
The COM code call is as below.  The return value in pv_output  got set in "foobar" variable.
STDMETHODIMP CValidator::Validate(VARIANT *pv_input, VARIANT *pv_output,  VARIANT *pv_retval)
We tried to create some Test/Sample code for the above scenario and found out that pass by reference is not supported for JAVASCRIPT in ASP or ASPX.
1) Created a  Foobar.asp / Foobar.aspx   with VBScript and the  code runs perfectly  with value in foobar variable as below.
    Foobar.aspx also works fine with below sample.
Foobar.asp :
<%@ Language=VBScript CODEPAGE=65001%>

<%

Function genValidationResponse

    Dim valob

    Dim retval, foobar

    Dim flexPress

    Dim req

    req  ="<VS_REQUEST><SERVICE_ID>br_v_source_ccy</SERVICE_ID></VS_REQUEST>"

    Set valob = CreateObject("Validation.Validator.1")

    retval = valob.Validate(req, foobar)

    genValidationResponse = foobar

    set flexpress = nothing

    set valob = nothing

    set xmldocR = nothing

End Function

%>
<%
    Response.Write (genValidationResponse())
%>

2) Created a  FoobarJS.asp/ FoobarJS.aspx  with  JavaScript  .This fails  and foobar is undefined.
     Same behaviour for FoobarJS.aspx. It returns foobar undefined.
FoobarJS.asp :
 <%@ Language=JavaScript CODEPAGE=65001%>

<script language="JavaScript" runat="Server">

function genValidationResponse(){

    var valob;

    var retval;

    var foobar;

    var req  ="<VS_REQUEST><SERVICE_ID>br_v_source_ccy</SERVICE_ID></VS_REQUEST>";

    valob = new ActiveXObject("Validation.Validator.1")    ;

    retval = valob.Validate(req, foobar);

    return foobar;

}

</script>

<%

   Response.Write(genValidationResponse());

%>
HELP REQUIRED  :
We need help  to understand " How to access the reference variable value  set in  "VARIANT *pv_output"     from Javascript  present in asp or aspx code.
it is possible by using RCW concept

推荐答案

问题已解决::

我们可以通过ASP.Net中的RCW概念将引用变量访问JavaScript.
要生成RCW,请参考下面的链接
http://msdn.microsoft.com/en-us/library/tt0cf3sx%28v = vs.80%29.aspx [ ^ ]

将此新的DLL放入项目的bin目录中,并将其导入到ASPX页面中.
下面是正在运行的ASPX代码:

Problem was solved::

We can access the reference variable into JavaScript by RCW concept in ASP.Net

To Generate RCW refer below link
http://msdn.microsoft.com/en-us/library/tt0cf3sx%28v=vs.80%29.aspx[^]

Put this new DLL into bin directory of your project and import it into your ASPX page.
below is Running ASPX code:

<%@ Page Language="JScript" CODEPAGE=65001 debug="true"%>
<%@ Import namespace="ValidationdllLib" %>
<script language="JScript" runat="Server">


function InvokeValidation(){
    var valob : ValidationdllLib.Validator;
    var foobar : Object;
    var retval : Object;
    var req : Object; //Here we declare this as Object,and problem get solved.
    req = "<VS_REQUEST><SERVICE_ID>br_v_source_ccy</SERVICE_ID></VS_REQUEST>"
    valob = new ValidationdllLib.Validator;
    retval = valob.Validate(req, foobar);
    return foobar;
}


</script>
<%
Response.Write(InvokeValidation())
%>


ASP.NET的全部目的是摆脱诸如此类的东西.您可以在后面的代码中创建对COM对象的引用,然后在其中调用它.无论如何,js在客户端上运行,而ASP中的VBScript在服务器上运行.您的代码期望该组件存在于客户端.您应该在ASP.NET上进行一些阅读,很显然您不了解它,而现在,您正在创建的内容可能对该网站的ASP.NET表现很差. ASP.NET与asp的工作方式不同,它并不丑陋,没有危险,也不合逻辑.
The whole point of ASP.NET is to get rid of stuff like this. You can create a reference to your COM object in your code behind and call it there. In any case, js runs on the client, and VBScript in ASP runs on the server. Your code is expecting this component to exist on the client side. You should do some reading on ASP.NET, it''s clear you don''t understand it, and that right now, what you''re creating is probably a very poor ASP.NET implimentation of this site. ASP.NET does not work the same way as asp, it is not ugly, not hapazard and not illogical.


这篇关于ASP或ASPX不支持ActiveX组件的JavaScript通过引用传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆