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:
// Client-side Javascript code
// 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:
// Server-side C# code
// get the context service
var context = PageWorkItem.Services.Get<Sage.Platform.WebPortal.Services.ClientContextService>();
// check for the value set by the client-side code
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#.



