How can I send a message from Javascript to C# or VB?
For example, …
In the client side I have a background process that I need to send any data to my current App.
In VWG I have a javascript function called ‘SendMessage’
Public Sub SendMessage(ByVal str As String)
Dim strScript As String = String.Format(“document.getElementById(‘TRG_{0}’).contentWindow.SendMessageToComponent(‘{0}’, ‘{1}’);”, Me.ID, str)
VWGClientContext.Current.Invoke(Me, “eval”, New Object() {strScript})
End Sub
If I use this javascript ….. SendMessage(‘wwwwwwwwwwwwwwwwwwwwwwwwwww’);’
I receive in VB Funtion:
And in my code inside the App I have a Function that receive this data…
Public Sub ReceivePushData(d As String)
‘here the d string is my data = ‘wwwwwwwwwwwwwwwwwwwwwwwwwww’
End Sub
More simple… I need to comunicate something from client in javascript to my App in Vb.net or C#
Web methods are exposed automatically on top level controls (Desktop, Page, Form) and in the main application static class (Program). The methods on controls are instance methods, while the web methods in Program as static and accessible using the “App.” object in javascript.
The override you mention is correct and registers web methods on singe controls.
However, the code you are showing seems to be circular. Eval(“this.test(this.Button1.getLabel())”). It’s returning the label to the server by calling back a server methods when the server is calling the client. It seems that you want to read the label property from Button1 because it was changed from the client without a call to the server?
There are a number of properties in Wisej widgets that are automatically wired back – when they change on the client they also change on the server. Specifically: size, location, value, … depending on the widget. The label is not since it’s not a value that typically changes outside of the server control.
However, you can subscribe to the “changeLabel” event like this:
Override OnWebRender (as you did) and add this:
config.wiredEvents.Add(“changeLabel(Text)”);
Override OnWebEvent and add a case:
case “changeLabel”:
this.Text = e.Parameters.Text; break;
Now every time the label changes wisej will fire an event to the server.
You can also fire your own events using:
this.fireEvent(“myEventName”);
config.wiredEvents.Add(“myEventName”);
or
this.fireDataEvent(“myEventWithData”), {name:’test’, something: 12});
config.wiredEvents.Add(“myEventNameWithData(DataMember)”);
The data is assigned to the named property in parenthesis, whatever you name it (only one). Then on the server you will find it in e.Parameters.DataMember (or whatever you named it). It’s a dynamic property. So in the case above you will have:
e.Parameters.DataMember.name; // it’s “test”
e.Parameters.DataMember.something; // it’s 12
HTH. And this is all internal stuff and how all Wisej controls are built. Using a highly optimized JSON serializer, diffing engine, and dynamic objects all wired through events and callbacks.
ok solved, I have do this override
Protected Overrides Sub OnWebRender(<Dynamic> ByVal config As Object)
MyBase.OnWebRender(CObj(config))
config.webMethods = {“test”}
End Sub
create the test sub
<Wisej.Core.WebMethod>
Public Sub test(testo As String)
AlertBox.Show(testo)
End Sub
and call with this
Eval(“this.test(this.Button1.getLabel())”)
bye
Cristian
Beacause i’m old in desktop programming but I’m very newbie about javascript I have not total understand…
example: if with javascript I change a button label with:
this.setLabel(“FOO”);
how I comunicate this to my vb app?
thanks
Cristian
Fantastic, a developer that reads the documents. 🙂
You can either fire a message to a control or call a remote method.
Best,
Luca