Constructor vs Shown vs Open

If I put UI related code in the Constructor of a WebDialog, is that violating the admonition against putting UI related code in the Open event instead of the Shown event? I want to put WebDialog.Top and WebDialog.Left stuff in the Constructor that is relative to the WebPage.Height and WebPage.Width.

The admonition is against accessing other UI in the Open event. You’re welcome to set all the properties of the current object as you wish.

But if the WebDialog Open event is attempting to read properties of the WebPage it’s called from, does that count as accessing other UI?

Push the properties from the method calling the webdialog, just like you did with top and left in the other thread. You feed properties created beforehand on the dialog. Then in the shown event, you can use these properties to update the dialog UI if need be. Properties can be arrays, arrays of structures or multi-dimensional arrays, variants, whatever is appropriate. That works very well. If you need to update the webpage or webcontainer when you are done with the dialog, use a handler on the page for the dismissed event of the dialog and perform the updates there.

Unfortunately, the answer is, “It depends.” Yes, it is “other UI”, but if in your use case, you know that it’s always already fully set up before your WebDialog is opened (say, in response to user action) then it’s safe to do. You have to think through the interaction between the server and the client. The main problem people run into is trying to manipulate UI that has either hasn’t been created yet, or hasn’t been received by the browser yet. The big difference between desktop and web is that delay between when the server has processed its code and when the browser has received the result and fully processed and displayed it to the user. If you fall into that gap, you get in trouble.

Thanks, Tim. I get the general idea here. Since, in this case, the dialog would have been called via a button on a WebPage, then referencing that WebPage’s properties would be okay in the WebDialog’s Open event because the WebPage would have been created at that point.

I still prefer to push data from the page to the webdialog from the button action event code. The reason is that a given dialog could theoretically be used with different pages. It is easier to push the data from the page than refactor the dialog every time you want to pull from a new page.

Yep. That’s what I’m doing.