WebPage and WebUIControls shown order?

Hi Folks,

I’m wondering, when displaying a webpage with controls inside

is the shown event of the webpage fired before or after all shown events of the controls inside the webpage ?

how to be sure that all the controls are shown on the web page before setting values to them ?

I’ve found that this odrer seems random to me…

anyone ?

thanks.

Not sure how this works now that we are experimenting with “send event in batches”. And the async nature of web.
Maybe @Ricardo_Cruz can give us an idea.

and it seems that the shown event on a webuicontrol is not fired if the item is not enabled ?

why ?

if it is invisible ok for not firing shown, but not enabled ?

is there somewhere a diagram showing the possible events occuring on a webpage (or webdialog)

and the interactions between these events ? @Ricardo_Cruz or @Greg_O I need your help !

I would expect the shown event to fire when the control is shown, regardless of its enabled state.

2 Likes

I will try to build a demo project, but my actual findings are that a webbutton does never fire shown,

and an not visible item does not (but I”m ok with that) , and a non enabled item does not fire shown too…

I can confirm that WebButtons do raise Shown, I have some hacks that rely on it.

On a simple Webpage, or on WebDialog, WebPagePanel, WebTabPanel?

in a webdialog for my actual case, visible or not, enabled or not.

Is the webdialog a Xojo dialog or one WebSDK you created?
I hope you can create a sample project.

just a subclass of webdialog.

the only difference may be is that I have one of my sdk in this dialog. may be this interferes with the shown event ?

there are many webtextfields in this dialog, some fire shown, some don"‘t

the sample project seems mandatory now…

I would open the browsers debug tools and see if you’re getting a JavaScript error somewhere. That’s the only thing I can think of that would cause it to only sometimes fire.

1 Like

Every time something goes wrong, the debug tools are your best friend. Even when things seem Ok, the debug tools may show issues. Seems each browser implements its own set of features. Looks like having a standard implemented by all browsers developers is too much to ask fore.

Well, the major players all have their own engines, so yeah, they’re all different.

Douglas Crockford had a wonderful lecture at one point where he asks:

in a browser, how will the following html code appear:

<i>text</i>

The answers come fast and furious from his students. italic! Emphasized!

But the real answer he says is “however the browser chooses to render it”

Ultimately It’s up to the browser and its CSS and DOM how it appears.

2 Likes

ok. so about this problem.

there were no errors in the browser debugger, and definitely not related to my websdk’s

after a while I figured that the page (or dialog) shown event is fired before the webcontrols or websdks on the page

which leads me to this problem: how (and where in which event) do we know that all the controls of the page are shown ? I need this to fill values of the controls from a database. if the controls are not yet shown I fill values in nowhere and it leads to empty controls .

I managed to use a notifier class interface for every of my controls , that indicate “I’ve run the shown event’“ and the page or dialog can receive the notification and then only fill the controls with their values.

I still don’t understand why in the framework the shown event of the page is fired before the controls ?

Have you tried using a WebTimer?

In the WebDialog.Opening event you could put this code:

WebTimer.CallLater(0, WeakAddressOf FillControls)

And you fill the controls inside FillControls method.

I did not try because the different users of the website have very different link speed, so what value to set the timer to ? I prefered a method that tells the dialog or page each time all controls are really shown

Why do you need all the controls to be shown before populating them? Won’t it cause some flickering?

If you set the timer from the Opening event instead, with a 0 value, it will work no matter of the network speed.

1 Like

Sample project:

WebDialog-sample.xojo_binary_project.zip (11.3 KB)

My guess is custom controls that need to be reviewed based on this comment:

IIRC, the built in controls store their values in properties in JavaScript even if the control hasn’t been rendered yet. In fact, the last thing the controls do after receiving an update from the server is to request an update from the framework.

I haven’t seen your code, but I would say then that you should make sure your WebSDK controls follow the same pattern of storing the data in properties, and don’t just push values into the DOM because the control may not be rendered yet. This gives you the added bonus of being able to tell if the value has been changed since it was sent from the server.