Overview of Article
There are various screen events available in LightSwitch. At the moment, there isn’t very much documentation specifying the order in which these events fire.
The following post documents my findings in relation to the ordering of events.
Methodology
Having created a details screen based on a ‘Customer’ entity, this is a typical screen which is created by default. The name of the screen is ‘CustomerDetail’ and the name of the Customer entity is ‘Customer’.
Fig 1 Illustration of Details screen
The following screenshot shows the available events. There are 3 property/entity events and 7 screen events. ‘CustomerId’ is the name of the property that relates to the screen parameter.
Fig 2 Events that are available
In order to work out the order in which these events fire, I’ve written some code showing a message box on each event. Here are my findings:
Order of events when opening a screen
- New
- CustomerId_Changed
- CustomerDetail_InitializeDataWorkspace
- CustomerDetail_Created
- CustomerDetail_Activated
- Customer_Validate
- CustomerId_Validate
- Customer_Loaded
Order of Events when changing a field and clicking ‘Save’
- CustomerDetail_Saving
- Customer_Validate
- CustomerId_Validate
- Finalize
Order of Events when closing a screen with no changes
- CustomerDetail_Closing
- Finalize
Order of Events when closing a screen with unsaved changes and choosing to discard
Order of Events when closing a screen with unsaved changes and choosing to save
- CustomerDetail_Closing

Dialog now appears – we choose ‘Save’ - CustomerDetail_Saving
- Customer_Validate
- CustomerId_Validate
- Finalize
As a final note, the CustomerDetail_Activated will fire whenever you change focus to another screen and return to it. Hopefully, this post sheds a bit more light into the ordering of events.



Great work Tim!
Thanks for sharing..
Yann
Good stuff, thanks for putting this together!
Pingback: LightSwitch Screen Events Order | Hacking LightSwitch
I actually was browsing for tips for my personal
site and noticed your own post, “LightSwitch – In What Order
do Screen Events Fire? | Tim Leung’s Blog”, do you really mind in the event that I really use several of ur points? I am grateful ,Liliana
“LightSwitch – In What Order do Screen Events Fire?
| Tim Leung’s Blog” marykayschildcare certainly got myself simply hooked on ur page! I personallywill probably wind up being returning significantly more frequently. Thanks ,Kathrin