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

image

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.

image

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

  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
    image
      Dialog now appears – we choose ‘Discard’
  2. Finalize

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

  1. CustomerDetail_Closing
    image
    Dialog now appears – we choose ‘Save’
  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.

Technorati Tags: ,
About these ads

About dotnettim

Tim Leung is a Microsoft .Net / SQL Server developer based in England.
This entry was posted in LightSwitch. Bookmark the permalink.

5 Responses to LightSwitch – In What Order do Screen Events Fire?

  1. Yann says:

    Great work Tim!

    Thanks for sharing..

    Yann

  2. smagin says:

    Good stuff, thanks for putting this together!

  3. Pingback: LightSwitch Screen Events Order | Hacking LightSwitch

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

  5. Myrtis says:

    “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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s