WebControlSDK ControlID ?

I am trying to get a JavaScript to trigger an ExecuteEvent in a WebControlWrapper class I have added to a WebPage.

If I understand right, I should be able to do that through

Xojo.triggerServerEvent(controlID As String, eventName As String, userData As Array)

I have an issue with

I can get the control ID fine for a TextField with this :

ExecuteJavascript("alert(document.getElementsByName('txtcmp_code1')[0].id) ;  " )

But if I try to get the ID for my WebControlWrapper using the Xojo name the same way, I get a JavaScript error

Any pointer ? Thank you in advance.

Keep in mind that the only html code that is sent to the browser is sent by your control, so if you’re getting this error, I susp ct that you’re not setting the Name attribute (because you’re calling getElementsByName).

In the case of txtcmp_code1, that is the name of the control in Xojo. And this is set upon design, and is not writable.

But my problem is much worse than I thought : after dragging an instance of a basic WebControlWrapper with nothing into it over the WebPage, a run in the IDE results in “Launching” without the icon, and the program gets stuck there.

I shall have to study more in detail the examples using the same class to understand. Hope my old brain will get it.

Thank you.

OK. Making progress here :slight_smile:

I have renounced for the moment creating a new WebControlWrapper class from scratch. Instead, I am experimenting by modifying the HTMLArea example from the WebSDK/Examples folder.

This fires the Execute event in the WebControlWrapper and in there I was able to retrieve the elements of the JavaScript array. Good beginning. It should enable me to get back JavaScript variables in Xojo much more elegantly than by changing the HashTag.

Function SetupJavascriptFramework() As String ExecuteJavaScript("var fruits = [""Apple"", ""Orange"", ""Donkey""]") ExecuteJavaScript("Xojo.triggerServerEvent('"+me.ControlID+"', 'ExecuteEvent', fruits)") End Function

Edit : I have now successfully used the same kind of code from elsewhere. It is a great way to send back JavaScript variables to Xojo !

Make sure you read the docs about namespaces. That’s probably why you were crashing.

You are right, I had read too quickly the PDF Section 2. I will do that more calmly tomorrow.

Thank you.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.