jamador wrote
Hi there,
Sorry for saying i didn't get it what you are trying to say,
but i'm sure this is my lack of experience with this.
The way i've managed to get some sort of my inteded functionality was
- In Javascript i define a global var
var V_CALL_SERVER;
- Then a function to call the "doCallBack". setting the second parameter to the name of the function to diferentiate on the server side
function CALL_SERVER() {
dnn.xmlhttp.doCallBack('__DNNCAPISCPAGEID','CALL_SERVER',CALL_SERVER_RESULT,this,errorFunc);
}
- Then the function to receive the response and set the global var(V_CALL_SERVER) with the result
function CALL_SERVER_RESULT(result, ctx) {
V_CALL_SERVER=result;
}
-Ok now i can call anywhere in my code the function and get the result
in the global var
CALL_SERVER();
var result_from_call = V_CALL_SERVER;
------------------------------
- To diferentiate on the server side which function was called i'm using the dnn.xmlhttp.doCallBack second parameter
in this exemple "CALL_SERVER" also :
Public Function RaiseClientAPICallbackEvent(ByVal eventArgument As String)....
if eventArgument="CALL_SERVER" then
CALL_SERVER()
....
end function
Awkward ?? you bet, but it was the only way i've made it work, please show me a better way.
Also the second parameter (strArgument) was the way to pass arguments to the server side code, so
i'm still left with a problem, how to send data to the server.
Regards,
Joao Amador
First, let me start out by saying that I would be worried about using global variables in this manner. The reason for my worry is that you are doing async calls, and if 2 calls are made you have no way of distinguishing which result goes with which call, I suppose this could be a use of the context variable. The code you gave
CALL_SERVER();
var result_from_call = V_CALL_SERVER;
may just be an over simplification, but as it is written will not work, for when you invoke CALL_SERVER, then immediately attempt to get the results will not work async. If you are attempting synchronous calls, then it would work, but like I mentioned earlier is not recommended (especially if you need to support many browsers, for my IFrame implementation of the callback (used for Safari and Opera) does not support sync calls.)
To answer your question about passing in different arguments.
function CALL_SERVER() {
dnn.xmlhttp.doCallBack('__DNNCAPISCPAGEID','CALL_SERVER',CALL_SERVER_RESULT,this,errorFunc);
}
You have a hardcoded string in your sample. I suggest having this parameter be another funciton call or better yet have it reference a passed in parameter
function CALL_SERVER(theArgument) {
dnn.xmlhttp.doCallBack('__DNNCAPISCPAGEID',theArgument,CALL_SERVER_RESULT,this,errorFunc);
}