0

I have this class setter and getter

public class CallbackObjectForJs
{
    public int _flag = 3
    public int loopKe
    {
        set { _flag = value; }
        get { return _flag; }
    }
}

And, I already registered this class at the top

chromeBrowser.RegisterJsObject("aobjclass", new CallbackObjectForJs())

I already succeed to call class object c# to js and return value "3"

const string script = @"(function()
{
     var atemp = aobjclass.loopKe
     return atemp;
})();";

chromeBrowser.EvaluateScriptAsync(script).ContinueWith(x =>
{
    var response = x.Result;

    if (response.Success && response.Result != null)
    {
         this.Invoke((MethodInvoker)delegate
         {
              int atemp = (int)response.Result;
              MessageBox.Show(atemp.ToString());     //show value "3"
         });
    }
});

But, in the next process I change my _flag value

CallbackObjectForJs _classJs = new CallbackObjectForJs();
int aflag = _classJs._flag;
_classJs._loopke = aflag + 1;

In C# the value has been changed "4", but when I call again this class in cefsharp javascript. The value still not change with value "3"

Please help me to solve this problem. Thanks

Yashar Aliabbasi
  • 2,663
  • 1
  • 23
  • 35
  • 1
    You need to keep a reference to the object you bound and update that. – amaitland May 02 '17 at 07:43
  • @amaitland: thanks for your response sir, but I think I've been keeping that. Because I use the global class variable _classJs . Or There is another way to keep a reference sir ? Thanks – rizkidzulkarnain May 02 '17 at 07:59
  • Review your code again, look at the register line, your not passing in a global reference to anything, your creating a new object and ignoring the reference. – amaitland May 02 '17 at 08:29
  • what should I do sir ? please give me an example Thanks @amaitland – rizkidzulkarnain May 03 '17 at 01:03
  • Based on the code above your problem is trivial, look at it again in detail, ask someone you work with for help. I'm sure you can figure it out. – amaitland May 03 '17 at 05:54

0 Answers0