Skip to main content
deleted 39 characters in body
Source Link
h0ch5tr4355
  • 2.2k
  • 4
  • 37
  • 54

I have following javascript function in my HTML document:

function jsFunction(string, jsonArray, string) { ... }

An example of jsonArray would be following:

[
{"name":"foo", "value":"21980"},
{"name":"bar", "value":"100"},
{"name":"foo", "value":"27492328"},
{"name":"bar", "value":"WEB21980001831"}
]

I followed the instructions from the post "https://stackoverflow.com/questions/16898731/creating-an-json-array-in-c-sharp" in order to create a JSON Array object in C#.

From my Windows Form I should be able to call the JavaScript function like this:

 Object[] jsParams = new Object[3];
 jsParams[0] = (Object)"test";
 jsParams[1] = new
 {
     items = new[] {
         new {name = "foo" , value = "21980"}, 
         new {name = "bar" , value = "100"}, 
         new {name = "foo" , value = "27492328"}, 
         new {name = "bar" , value = "WEB21980001831"}
     }
 };
 jsParams[2] = (Object)"content";
 jsParams[3] = (Object)"test";

 this.webBrowserCtl.Document.InvokeScript("jsFunction", jsParams);

However, it doesn't work. Did I forget something?

I have following javascript function in my HTML document:

function jsFunction(string, jsonArray, string) { ... }

An example of jsonArray would be following:

[
{"name":"foo", "value":"21980"},
{"name":"bar", "value":"100"},
{"name":"foo", "value":"27492328"},
{"name":"bar", "value":"WEB21980001831"}
]

I followed the instructions from the post "https://stackoverflow.com/questions/16898731/creating-an-json-array-in-c-sharp" in order to create a JSON Array object in C#.

From my Windows Form I should be able to call the JavaScript function like this:

 Object[] jsParams = new Object[3];
 jsParams[0] = (Object)"test";
 jsParams[1] = new
 {
     items = new[] {
         new {name = "foo" , value = "21980"}, 
         new {name = "bar" , value = "100"}, 
         new {name = "foo" , value = "27492328"}, 
         new {name = "bar" , value = "WEB21980001831"}
     }
 };
 jsParams[2] = (Object)"content";
 jsParams[3] = (Object)"test";

 this.webBrowserCtl.Document.InvokeScript("jsFunction", jsParams);

However, it doesn't work. Did I forget something?

I have following javascript function in my HTML document:

function jsFunction(string, jsonArray, string) { ... }

An example of jsonArray would be following:

[
{"name":"foo", "value":"21980"},
{"name":"bar", "value":"100"},
{"name":"foo", "value":"27492328"},
{"name":"bar", "value":"WEB21980001831"}
]

I followed the instructions from the post "https://stackoverflow.com/questions/16898731/creating-an-json-array-in-c-sharp" in order to create a JSON Array object in C#.

From my Windows Form I should be able to call the JavaScript function like this:

 Object[] jsParams = new Object[3];
 jsParams[0] = (Object)"test";
 jsParams[1] = new
 {
     items = new[] {
         new {name = "foo" , value = "21980"}, 
         new {name = "bar" , value = "100"}, 
         new {name = "foo" , value = "27492328"}, 
         new {name = "bar" , value = "WEB21980001831"}
     }
 };
 jsParams[2] = (Object)"test";

 this.webBrowserCtl.Document.InvokeScript("jsFunction", jsParams);

However, it doesn't work. Did I forget something?

Source Link
h0ch5tr4355
  • 2.2k
  • 4
  • 37
  • 54

How can I pass a JSON array to a javascript function in the C# WebBrowser Control?

I have following javascript function in my HTML document:

function jsFunction(string, jsonArray, string) { ... }

An example of jsonArray would be following:

[
{"name":"foo", "value":"21980"},
{"name":"bar", "value":"100"},
{"name":"foo", "value":"27492328"},
{"name":"bar", "value":"WEB21980001831"}
]

I followed the instructions from the post "https://stackoverflow.com/questions/16898731/creating-an-json-array-in-c-sharp" in order to create a JSON Array object in C#.

From my Windows Form I should be able to call the JavaScript function like this:

 Object[] jsParams = new Object[3];
 jsParams[0] = (Object)"test";
 jsParams[1] = new
 {
     items = new[] {
         new {name = "foo" , value = "21980"}, 
         new {name = "bar" , value = "100"}, 
         new {name = "foo" , value = "27492328"}, 
         new {name = "bar" , value = "WEB21980001831"}
     }
 };
 jsParams[2] = (Object)"content";
 jsParams[3] = (Object)"test";

 this.webBrowserCtl.Document.InvokeScript("jsFunction", jsParams);

However, it doesn't work. Did I forget something?