Sunday 17 February 2013

In What Order do Screen Events Fire?

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’.

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.


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

  1. New
  2. CustomerId_Changed
  3. CustomerDetail_InitializeDataWorkspace
  4. CustomerDetail_Created
  5. CustomerDetail_Activated
  6. Customer_Validate
  7. CustomerId_Validate
  8. Customer_Loaded

Order of Events when changing a field and clicking ‘Save’

  1. CustomerDetail_Saving
  2. Customer_Validate
  3. CustomerId_Validate
  4. Finalize

Order of Events when closing a screen with no changes

  1. CustomerDetail_Closing
  2. Finalize

Order of Events when closing a screen with unsaved changes and choosing to discard

  1. CustomerDetail_Closing
  2. Finalize

Order of Events when closing a screen with unsaved changes and choosing to save

  1. CustomerDetail_Closing
  2. CustomerDetail_Saving
  3. Customer_Validate
  4. CustomerId_Validate
  5. 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.

For more detailed screen shots please click here

No comments: