[SOLVED] Get the return value of the javascript function embedded in the widget control

Answered Closed
0
0
Hello,
A program with a javascript function embedded in the widget control
Is it possible to set the return value of?

I want to get back to the javascript function for the following:
————————————————– —————————
javascript side:
function getData () {
return true; // <—- Value to return to the form side
}
————————————————– —————————
  • You must to post comments
Best Answer
0
0

Hi Takao,

Yes it is!

Set up your JavaScript like this (Note: if you put a function getData() { } declaration in the initScript it will run as soon as the app launches, that’s why we use this.getData):

this.getData = function() {

       return true | false;

}

 

On the C# side:

private async void button5_Click(object sender, EventArgs e)

{

        var result = await this.widget1.CallAsync("this.getData");

        AlertBox.Show(result.ToString());

}

 

You can also add the [WebMethod] attribute to any function in C# and call that from JavaScript!  Web methods are exposed automatically on top-level controls (Desktop, Page, Form) and in the main application static class (Program).

For Example:

JavaScript Side:

this.hello = function() {

        App.HelloWorld();
}

 

C# Side:

[WebMethod]

public void HelloWorld() {

        AlertBox.Show("Hello, World!");
}

 

Check out these documents for more information and detail:

https://wisej.com/docs/2.0/html/JavaScript.htm

https://wisej.com/docs/2.1/html/JavaScriptObjectModel.htm

https://wisej.com/docs/2.0/html/T_Wisej_Web_Widget.htm (Call / Eval)

https://wisej.com/support/question/how-can-i-send-a-message-from-javascript-to-c

 

Best,

Levie

  • You must to post comments
0
0

Levie (ITG)

Thank you.

  • You must to post comments
Showing 2 results