Quantcast
Channel: SalesLogix – Customer FX
Viewing all articles
Browse latest Browse all 169

Passing Values from Client-Side Javascript to Server-Side C# Actions in Infor CRM Web

$
0
0

There are more and more parts in Infor CRM (Saleslogix) that use client-side code, however, the application itself does still rely heavily on C# server-side actions in postbacks for most of the heavy work. Mixing the two worlds can sometimes be necessary to have things work seamlessly.

Passing values from your client-side code to the server-side code can easily be done using the ClientContextService. There are both Javascript & C# versions of the ClientContextService and they both share the same data. You can use the Javascript ClientContextService and add & remove values and in your server-side code you can use the .NET ClientContextService to do the same. You can set values in Javascript and read them from C# and also set values in C# and read them in your Javascript code. Let’s take a look at how it works.

The ClientContextService

The following Javascript sets some values in the context service:

// get the context service
var context = Sage.Services.getService('ClientContextService');
// check if our value already exists. If so, update it, if not add it
if (context.containsKey('Foo')) {
    context.setValue('Foo', 'Hello from the other side');
}
else {
    context.add('Foo', 'Hello from the other side');
}

This C# code in a postback reads the values set from the Javascript code above:

// get the context service 
var context = PageWorkItem.Services.Get<Sage.Platform.WebPortal.Services.ClientContextService>();
if (context.CurrentContext.ContainsKey("Foo"))
{
    var fooValue = context.CurrentContext["Foo"];
    // do something with fooValue...
}

We could easily do the same to make values available in our Javascript code from C#.


Viewing all articles
Browse latest Browse all 169

Latest Images

Trending Articles



Latest Images