WebDialog single instance

Hi all,

Is there a good way to know if a webdialog is already opened (when created on the fly) ?
I need this to prevent the dialog to open twice if the user click to fast on the button (that opens the dialog)
This does happen if the dialog is quite big (and slow to display).
Finally, the question is :
- Can a WebDialog be mono-instance ?

Thanks

Nobody on this one ?

Don’t really know but you might be able to set a property in Session to True prior to opening the dialog.
When you click the button, check if the property is true or false and only show the dialog it it’s false.
When the dialog is dismissed, set the property to false again.

Have not tried this though.

Thanks for you reply Albin.
But this solution doesn’t work. It’s too late to set the property in the session object, the second event is already been executed before.

Is it the same if the dialog isn’t created on the fly?
(dragged onto the WebPage)

[quote=24295:@Albin Kiland]Is it the same if the dialog isn’t created on the fly?
(dragged onto the WebPage)[/quote]
No, if the dialog is not created on the fly, every thing works well…

If you disable the button in it’s action event before you create the dialog?
Really just throwing out simple ideas here :wink:

[quote=24299:@Albin Kiland]If you disable the button in it’s action event before you create the dialog?
Really just throwing out simple ideas here ;)[/quote]
It’s the same. Xojo is running all the code at once so whatever you set before showing the dialog is done at the same time.
The only possible solution I think about is doing the dialog creation in a timer… but that’s a quite “ugly” workaround…

This might be way off but try a WebTimer with a short period.
Button.Action:
me.Enable=False
Timer1.Mode = 1

Timer1.Action:
showthedialog

There sure must be a better way though :confused:
Maybe someone else can chime it :slight_smile:

In the WebDialog subclass, create a Shared property :

OpenedInSession as Dictionary

In the code that opens the dialog, add:

If not Dialog1.OpenedInSession.HasKey(Session.Identifier) then Dialog1.Show End If

In the open event of the subclass:

OpenedInSession(Session.Identifier) = True

In the Dismissed event:

OpenedInSession.Remove(Session.Identifier)

Thanks Greg !
I’ll try this right away.

I’ve tried Gred’s solution and it works… with little fixes :wink:

Replace :

If not Dialog1.OpenedInSession.HasKey(Session.Identifier) then Dialog1.Show End If
by :

if Dialog1.OpenedInSession = nil then Dialog1.OpenedInSession = new Dictionary If not Dialog1.OpenedInSession.HasKey(Session.Identifier) then Dialog1.Show End If
otherwise, the NilException is raised when the dialog is created

Replace

OpenedInSession(Session.Identifier) = True

by :

OpenedInSession.Value(Session.Identifier) = True

otherwise, there’s a compilation error

BTW, how to free the new dialog instance if it’s created but cannot be shown (alread showned) ?

Thanks Valry. Yes, you free the instance with the Remove method in the Dismissed event.