How to: Handle Screen Events in a Mobile Client for a LightSwitch App


For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

As you develop an HTML mobile client in LightSwitch app, you can write JavaScript code that runs when a user initiates a certain event. For example, you can write code that runs when a user chooses a button on a screen in your client.

You can write the following kinds of methods to run when a user takes a certain action:

  • Button methods run when a user chooses a button.

  • General methods run when a user loads data, saves data, or closes a screen.

  • Access control methods run when a user tries to perform a task that requires certain permissions.

For more information about these kinds of methods, see the tables after the following procedure.

To handle an event

  1. In Solution Explorer, open the screen that you want to modify.

    The Screen Designer opens.

  2. On the Screen Designer toolbar, open the Write Code list, and then choose the appropriate method

    The Code Editor opens.

  3. In the new method, enter the code that you want to run when the event occurs.

The following tables list methods that can run when a user interacts with a screen. All of these methods run on the client tier.

Button MethodDescription
ButtonName_executeCalled when a user chooses the button that’s associated with the method. Applies only to buttons based on custom methods.
General MethodsDescription
ScreenName_createdCalled just after the screen appears.
ControlName_postRenderCalled after the HTML for a control is created.
ControlName_renderCalled to create the HTML for a custom control.
ScreenName_beforeApplyChangesCalled just before a screen is is closed and data is saved.
Access Control MethodsDescription
MethodName_canExecuteCalled before a method runs. LightSwitch calls this method to check permissions for the current user.

How to: Modify a Screen by Using Code
HTML Client Screens