Trigger an action from a button click event

This exercise describes how to use a Click event to trigger an action when the button on a form is pressed.

To trigger an action on the click of a button:

  1. Select the button and then open the Events page in the Properties pane.
  2. Events define the interaction between the user and a control. The mouse can be used, for example, to click a button or give focus to a button. Scripts can be associated with an event to trigger other events or actions.

  3. In the Actions section of the pane, double click the Click property to create a button click event.
  4. This button click event can be used to call an action in the code.

    To view the code for the form,

    1. Press F7 to open the code in a new tab.

    The button click event you created is shown in the last line of code, as the newest addition to the form.

    In this example, the buttons are being used to change the Source property for a WebView2 control to a different URL. This provides the user with a method of changing the web page displayed in the browser. The new click event can be configured to open a third site. In this case, we will add a link to the Microsoft® Technical Documentation online.

With the code for the button click event added,

  1. Click Save.
  2. Click the Main tab to return to the form.
  3. Run the form using the Start Debugging button in the toolbar.
  4. Click the button configured for the new event to open the Microsoft® Technical Documentation page.

More information on using code to configure elements of Flow forms is contained in Working with Scripts.