•  
  •  
  •  
 

RemoteInvoke - Specifying the javascript return function?

Last post 24 May 2007, 10:57 AM by Vodzurk. 4 replies.
Sort Posts: Previous Next
  •  23 May 2007, 11:25 AM 12080

    RemoteInvoke - Specifying the javascript return function?

    Hi,

    I've been using the RemoteInvoke functionality of WebImageViewer... and so far it's great.

    But I was wondering if it is possible to define the javascript function which would handle the result?  From the documentation, I can see that it is possible to use a generic function for all return values as such:

    WebImageViewer1.RemoteInvoked = OnRemoteInvoked;
    function OnRemoteInvoked(){
       var success = WebImageViewer1.getReturnValue();
       if (success == true){
          alert('WaterMark Succeeded.');
       }
       else {
          alert('WaterMark Failed.')
       }
    }

    In Ajax.Net 2.0 (or whatever it's called today), you can use WebMethod's, specifying which JavaScript function will handle the returned result:

    PageMethods.SomeServerSideMethod( SomeParameter, SomeOtherParameter, JavaScriptReturnHandler);

    However, using this with WebImageViewer means somehow passing a reference back through as it seems WebMethod's must be static, blocking access to any page objects (unless they're session'd, which I'd prefer not).

    Alternatively, I could pass back a comma-delimited (or something safer) string and use the generic handler.

    /ramble

    Filed under:
  •  23 May 2007, 11:41 AM 12081 in reply to 12080

    Re: RemoteInvoke - Specifying the javascript return function?

    Here is some JavaScript code that I used to create a custom return event for a RemoteInvoke:

    function OpenImage(url){
       WebImageViewer1.RemoteInvoked = OpenImageCallBack;
       WebImageViewer1.RemoteInvoke('Remote_OpenImage', new Array(url));
    }

    function OpenImageCallBack(){
       WebImageViewer1.RemoteInvoked = function(){};
       WebThumbnailViewer1.OpenUrl(WebImageViewer1.getReturnValue());
    }

  •  24 May 2007, 4:35 AM 12084 in reply to 12081

    Re: RemoteInvoke - Specifying the javascript return function?

    Would that work with multiple custom return events?

    Like:

       WebImageViewer1.RemoteInvoked = OpenImageCallBack;
       WebImageViewer1.RemoteInvoke('Remote_OpenImage', new Array(url));
       WebImageViewer1.RemoteInvoked = ResizeWindowCallBack;
       WebImageViewer1.RemoteInvoke('Remote_Resizer', new Array(x,y));

    allowing for the results of each invocation to fire off specific callbacks at the clientside?

  •  24 May 2007, 9:21 AM 12086 in reply to 12084

    Re: RemoteInvoke - Specifying the javascript return function?

    No, they won't work that way... you will have to chain them together like this:

    // this function starts the chain
    function OpenImage(url){
       WebImageViewer1.RemoteInvoked = OpenImageCallBack;
       WebImageViewer1.RemoteInvoke('Remote_OpenImage', new Array(url));
    }

    function OpenImageCallBack(){
       WebImageViewer1.RemoteInvoked = ResizeWindowCallBack;
       ...
    }

    function ResizeWindowCallBack(){
       WebImageViewer1.RemoteInvoked = function(){};
       ...
    }

  •  24 May 2007, 10:57 AM 12093 in reply to 12086

    Re: RemoteInvoke - Specifying the javascript return function?

    Ah, ok.  I'll stick with passing the invoked function name back to the callback, it seems to be a more flexible option.

    (Possibly not the best example of it in use at the moment, as both invocations do the same thing with the result)

    function OnRemoteInvoked()
    {
     
    var arrResult = wiv.getReturnValue().split(",");

     
    if( null != arrResult[0] )
      {
       
    switch( arrResult[0] )
        {
         
    case "ZoomWidth()":
         
    case "ZoomExtents()":
            document.getElementById(
    "txtZoomLevel").value = arrResult[1];
           
    break;
        }
     
    }
    }

View as RSS news feed in XML