PostCustomAction communicate back to client

Discussions about DocuVieware integration in GdPicture.NET.
Post Reply
pete
Posts: 21
Joined: Wed Mar 25, 2015 10:11 pm

PostCustomAction communicate back to client

Post by pete » Thu Oct 08, 2015 12:37 pm

Hi,

is there a way how PostCustomAction can communicate with a client? My example scenario is this: I would like to iterate through all annotations on the page, find a sticky note and return its text to a client. I have done everything so far, but I do not know how to send data back to client (via ajax?) so I can manipulate the with JS.

Code: Select all

//client side
var returnedObject = DocuViewareAPI.PostCustomServerAction('DocuVieware1', true, 'MyOwnCustomAction', []);


//server side
private void handleCustomAction(object sender, CustomActionEventArgs e)
{

 if (e.actionName == "MyOwnCustomAction")
 {
  ///I want to return an object here
 }
}

pete
Posts: 21
Joined: Wed Mar 25, 2015 10:11 pm

Re: PostCustomAction communicate back to client

Post by pete » Thu Oct 08, 2015 1:09 pm

So far, I have been able to solve it by creating a global static class in file "Global.aspx"

Code: Select all

    public class viewerRefrence
    {
        public static DocuVieware reference { get; set; }
    }
then on Page_load() I reference it:

Code: Select all

viewerRefrence.reference = DocuVieware1;
After this, I am able to call controller action via ajax and get what I need, but I do not think this is a good solution. Is there a better way?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: PostCustomAction communicate back to client

Post by Loïc » Fri Oct 09, 2015 11:11 am

Hi,

Yes there is. You can pass any kind of parameters to a custom action and obtain a result.

Let's have a look on the PostCustomServerAction prototype:

Code: Select all

PostCustomServerAction: function (docuViewareID, async, actionName, params, success, error) 
The interesting part for you is the success trigger.

Here an example based on our barcode recognition demo, that will show in client side the result obtained from the server action:

Code: Select all

function onBarcodeRecognitionSuccess(result) {
     alert("result: " + JSON.stringify(result));
}

function barcodeRecognition() {
    var json = {
        readlinear: false,
        readqrcode: false,
        readmicrorrcode: false,
        readdatamatrix: false,
        readpdf417: false
    };
    if ($('#chk-linear').is(":checked")) {
        json.readlinear = true;
    }
    if ($('#chk-qr').is(":checked")) {
        json.readqrcode = true;
    }
    if ($('#chk-microqr').is(":checked")) {
        json.readmicrorrcode = true;
    }
    if ($('#chk-datamatrix').is(":checked")) {
        json.readdatamatrix = true;
    }
    if ($('#chk-pdf417').is(":checked")) {
        json.readpdf417 = true;
    }
    DocuViewareAPI.PostCustomServerAction('DocuVieware1', true, "barcodeRecognition", json, onBarcodeRecognitionSuccess);
}

As you can see we are getting a result object, as parameter of the success trigger.

This object result is obtained from the server side. You can assign it during the CustomActionsHandler event. IE:

Code: Select all

private void CustomActionsHandler(object sender, CustomActionEventArgs e)
{
  e.result = new object();
}
I can imagine this is not super clear, so please Peter, let me know if you need any further information.

Cheers,

Loïc

pete
Posts: 21
Joined: Wed Mar 25, 2015 10:11 pm

Re: PostCustomAction communicate back to client

Post by pete » Fri Oct 09, 2015 12:07 pm

Hi Loic,

thank you! Everything is clear and works :)

Peter

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest