Displaying text from a class on a page

hello,

i starting to use webapp coming from desktop

i have a organisation problem, to update text areas
in desktop you do
mywindow.myTextarea.text = “put something”

but in web app,
it seems you can only do
myTextarea.text = “put something” coming from a button or an element inside the page

if it is in the app or session, or in a class
mypage.myTextarea.text = “put something”
will bring nilobjectexecption

so i’m trying from the app or the session but got nil exeption too

how do i refer to update textarea from outside the page? must be simple, excuse my noobiness :slight_smile:

Hey Phillippe,

As far as I know, that could work, can you share an example project to see what’s going on?

I prefer to expose computed properties, instead of making controls public (even in desktop apps). So when you update a computed property, it will update the control.

Hope this helps.

you need the valid page/object reference.
https://documentation.xojo.com/api/web/websession.html
https://documentation.xojo.com/api/web/websession.html#websession-pages
https://documentation.xojo.com/api/web/websession.html#websession-currentpage
use a break point and look into debugger if your object exists.

in fact i made more tests, and use session to store my class instance
it’s a urlConnection

it’s when the content received is triggered that i want to display some text on page.
i made a small project, that crashes when the content received wants to send text to page

https://ota.pe/contentReceived.zip

try this because you are inside of this class


Sub ContentReceived(URL As String, HTTPStatus As Integer, content As String) Handles ContentReceived
  'Session.myClass.hisString = content
  hisString = content
End Sub

give this class the page object in Page Open at new wClass(self)
it means change the construtor
and memory the page object for later user in a property.
seems you can not access the page direct by name in ContentReceived.

1 Like

The strategy that I use for server-side processes like urlConnection is to create an instance of urlConnection in the Session class, and create its Events as Methods in the Session class (using AddHandler).

However, I never allow urlConnection to touch the UI. Instead, for example, my handler method for contentReceived would write received data into a pre-defined text property of the Session class. (I do this because urlConnection is asynchronous, and we never know when the content will be received.

I then have a WebTimer object that is in the WebPage class, and I set that timer running in continuous mode (1s interval, perhaps) when urlConnection is first called. The timer’s Action event looks for the text property in Session, and when that property is no longer blank, the timer can be turned off and the text can be copied from Session to a label or textArea on the webpage.

Because the timer is within the webpage class, its webpage (and therefore its textArea) are always in scope whenever the page is on display. urlConnection can do its thing, and the timer can do its thing - the two never meet. Keeping the UI separate from background processes like urConnection always seems to work well.

1 Like