JavaScript Object Model
Wisej keeps the server and the client browser always in sync. Including the application's UI object model. This means that you can write JavaScript code that interacts with the application's controls in the browser and simultaneously update their server-side related components.

UI Object Model

Wisej registers all the top-level windows and all the children, hierarchically and recursively, with the browser using App as the root object. For example, the simple HelloWorld tutorial application registers this JavaScript object: App.Window1. You can see the object model using F12 and typing App. in the console.
Child objects are reachable as members of their parent control, i.e.: App.Window1.button1.
The example code below shows how to change the text of button1 using JavaScript and how to trigger the event on the server-side. Type the code in the browser's console (F12).
JavaScript
1
App.Window1.button1.setLabel("Hello JavaScript");
2
App.Window1.button1.execute();
Copied!
Wisej JavaScript widgets are all derived from Qooxdoo's widget. See Qooxdoo's API Qooxdoo's API reference to learn which methods and properties to use.
In case there is a name collision - a child control name collides with a widget method or property - Wisej will ignore the child control name. You can always reach it using parent.getChildControls()[index]. However, if the name collision is among components - an application creates 10 Window1 objects - Wisej converts the member into an array: i.e. App.Window1[0], App.Window1[1], ...

Remote Methods

Wisej also supports calling server-side methods from the client. Any public method declared in a visual component with the [Wisej.Core.WebMethod] attribute becomes a remote method. You can call it from the browser, passing arguments and even receiving the return value from the server.
You may also declare public static [Wisej.Core.WebMethod] methods in your Program.cs class and then find them on the client-side registered as methods of the App object.
The example below shows how to add a remote method to a form and to the application, the application method shows how to return a value.
C#
VB.NET
1
public class Window1: Wisej.Web.Form
2
{
3
...
4
[WebMethod]
5
public void Hello(string name)
6
{
7
// Change the window title.
8
this.Text = "Hello " + name;
9
}
10
}
11
12
...
13
14
public static class Program
15
{
16
...
17
[WebMethod]
18
public static int Hello(string name)
19
{
20
this.Text = "Hello " + name;
21
22
// Return the lentgh of the parameter.
23
return name.length;
24
}
25
}
Copied!
1
Public Class Window1
2
Inherits Wisej.Web.Form
3
4
...
5
<WebMethod>
6
Public Sub Hello(name As String)
7
8
' Change the window title.'
9
Me.Text = "Hello " + name
10
11
End Sub
12
13
End Class
14
15
...
16
17
Module Program
18
...
19
<WebMethod>
20
Public Function Hello(name As String) As Int32
21
22
Me.Text = "Hello " + name
23
24
' Return the length of the parameter. '
25
Return name.Length
26
27
End Function
28
End Module
Copied!
The following code shows how to use the web methods defined above from JavaScript, you can type the code in the browser's console.
JavaScript
1
// Invoke the method Hello on the current instance of Window1.
2
App.Window1.Hello("Mary");
3
4
// Invoke the static method Hello on the Program class, running using the current session.
5
// And display the returned value in browser alert.
6
App.Hello("Jack", function(result){ alert(result); });
Copied!
Only web methods declared in top-level containers (Page, Form, Desktop) are registered with the client widget automatically.
Web methods declared in child control classes can be used, but need to be explicitly registered by overriding OnWebRender() and adding the webMethods array to config.webMethods = new[]{"method1", "method2"};
Last modified 8d ago
Export as PDF
Copy link