0
votes

I have a two tier VisualStudio C# Lightswitch application that i'd like to pass a variable from the client to server.

Problem: When i try running my application the global variable global.WorkOrder is always null. I've tried commenting out all the class references on the server and hardcoded a constant string into global.WorkOrder on the client....but it remains null. Here's some code.

Client:

public partial class AddPart
{
    partial void Input_Changed()
    {
      UserCode.Globals global = new UserCode.Globals();
      global.WorkOrder = parts[7];

Server:

namespace LightSwitchApplication
{
    public partial class DataService
    {
        partial void Instances_Inserted(Instance entity)
        {
            UserCode.Globals global = new UserCode.Globals();
            InstanceInfo w = this.DataWorkspace.AUTOData.InstanceInfoes.AddNew();
            w.InfoContent = global.WorkOrder;

I've also created a Class1 that lives on the server in a UserGroup folder. The class has been 'linked' on the client side.

Class:

namespace LightSwitchApplication.UserCode
{
    public class Globals
    {
            public string WorkOrder { get; set; }

The code compiles without errors but something isn't correct. What am I doing wrong? Sorry for the beginner question, and please let me know if you need more information to help. Thanks!

1
As a troubleshooting effort i went in the class and hardcoded public string Workorder = "Mike". This pushes Mike out to both client and server variable declarations, even though in the client i've got global.WorkOrder = parts[7]. parts[7] definitely has a value but global.Workorder is still not being written too on the client.Ben Goldstein

1 Answers

0
votes

Turns out my global variable is working fine, I have another issue with a line of code that commits the record entry to my database. I execute the commit on the client before the server is data is committed. As soon as i commit the variable it becomes null. This is more of a code structure thing with the two tier system that i need to figure out.