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

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.

Screen Event Methods

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 Method

Description

ButtonName_execute

Called when a user chooses the button that’s associated with the method. Applies only to buttons based on custom methods.

General Methods

Description

ScreenName_created

Called just after the screen appears.

ControlName_postRender

Called after the HTML for a control is created.

ControlName_render

Called to create the HTML for a custom control.

ScreenName_beforeApplyChanges

Called just before a screen is is closed and data is saved.

Access Control Methods

Description

MethodName_canExecute

Called before a method runs. LightSwitch calls this method to check permissions for the current user.

See Also

Tasks

How to: Modify an HTML Screen by Using Code

Other Resources

HTML Client Screens for LightSwitch Apps