Text control not updating

I have a web project with a text control called txtNotice. Its default value is “Please wait”

On the page open event I do txtNotice.text = “Hello”

I then do some processing in a timer and as things happen I change the txtNotice text at the end I show another page. The problem is that the text never changes from “Please wiat”, do I need to tell the control to update after I change its value or am I doing something wrong?

[quote=74684:@Nathan Wright]I have a web project with a text control called txtNotice. Its default value is “Please wait”

On the page open event I do txtNotice.text = “Hello”

I then do some processing in a timer and as things happen I change the txtNotice text at the end I show another page. The problem is that the text never changes from “Please wiat”, do I need to tell the control to update after I change its value or am I doing something wrong?[/quote]

So, ignoring the timer for now, the text should change to “Hello”. Set a breakpoint in the Open event, just after the txtNotice.text = “Hello” line. Check the debugger - has the text changed?

Using the Open event is generally not a good idea. The Shown event is safer.

Guys, the problem as I understand it is not that the initial value is not getting set, it’s that the changed value set by the timer is not displaying.

Nathan: First, is this a WebTimer or just a Timer?

Second, where are you setting the timer to running? And at what period?

Finally, when you say you are doing some processing in the timer, how are you accomplishing this? Usually “processing” is done in a thread.

Basically this is what I am doing:

  1. User clicks a login button
  2. Please wait dialog is displayed which has the txtNotice control
  3. Timer is started (not web timer)
  4. In Timer Action Event the following happens:
    4a) Set txtNotice.text to “Please wait”
    4b) Set timer mode to off
    4c) Set txtNotice.text to “Connecting to server”
    4d) Do HTTP get request to check server is live
    4e) If result bad display error else continue
    3f) Set txtNotice.text to “Connecting to database”
    4f) Use db connect to talk to database
    4g) Set txtNotice.text to “Loading main menu”
    4e) frmMain.Show to display menu page

Just to let everyone know, I am new to Xojo and come from a vb background so OOPs etc is new to me so may well be doing this totally wrong :wink:

Right, but if you’re changing the text in Page.Open and that’s not happening, the timer is kind of irrelevant. As Bob says, move your initial text change to the Shown event (which kicks in whenever the page is actually displayed, as opposed to the Open event which happens when the page is about to be displayed - which should be fine for this, really).

I’d get that working first - keep it simple to start with!

Ok that worked but the timer bit still isnt so I removed timer and added the code to the Shown event of the dialog window and changed the code to

me.lblPleaseWait.Text = “test 1”

But it still isnt changing.

[quote=74761:@Nathan Wright]Basically this is what I am doing:

  1. User clicks a login button
  2. Please wait dialog is displayed which has the txtNotice control
  3. Timer is started (not web timer)
  4. In Timer Action Event the following happens:
    4a) Set txtNotice.text to “Please wait”
    4b) Set timer mode to off
    4c) Set txtNotice.text to “Connecting to server”
    4d) Do HTTP get request to check server is live
    4e) If result bad display error else continue
    3f) Set txtNotice.text to “Connecting to database”
    4f) Use db connect to talk to database
    4g) Set txtNotice.text to “Loading main menu”
    4e) frmMain.Show to display menu page[/quote]
    The problem is that you’re only using the timer to run all of the code one time, in one event. In order for the page/dialog/control to be updated, you have to allow the system time to refresh - allow the event loop to cycle. From the moment the timer action event fires until the end of the code you have in there, nothing is going to be updated on the screen. One messy way to accomplish this is to fire additional timers for each change in displayed text. But the better way is to use a thread to run the code, and a repeating webtimer to display the contents of some variable that you set from the thread (the thread can’t access the UI directly).

There’s an example in the Thread entry in the LR. Though it’s about a desktop app, the same mostly applies to a web app. The basic process is:

  1. Create a WebTimer with an Action event that checks/displays data from a page or session property
  2. Create a Thread instance (should be a property on the page or dialog)
  3. Assign the appropriate thread priority
  4. Assign the method for the thread to run with AddHandler
  5. Start the WebTimer
  6. Start the Thread

There are other thing to address, but hopefully this will get you started.

Is it really that difficult just to refresh a label on a page when you do something in the code? In vb you used to simply do a refresh on the label and it refreshed, is it not possible to do the same in Xojo?

No, it’s not difficult at all - setting the text property is enough. If you want to email me the project, I can take a quick look, if you like.

Thanks Gavin, I am going to create a new specific project to replicate the problem to make sure I am not being stupid. If that doesnt work I will email it to you.

Gavin, I have just emailed you a really simple example where the text is not updating.

Email on its way. I’ve simplified a couple of things and made a few session properties. Jay’s advice above is very sound above for when things get more complicated but this should get you started. HTH.