How to set the text of an Edit control when a button is pressed?

ImportantThe following article uses options that are available starting with the Enterprise edition and project type.

Very often it is necessary to update the text of an Edit control when the user clicks a button which resides on the same dialog. The content of the Edit control will be modified using a custom action without sequence (which is launched by an Execute custom action published event associated with the button control).

The general method to achieve this task consists in defining two published events associated with the button control:

  • An Execute custom action published event which invokes your custom action without sequence that sets a property. For simplicity, this property can be that attached to the Edit control. For more details on how to define such a Custom Action see Execute custom action on button push.
  • A Set installer property value control event which sets the property associated with the edit control to the value of the property set by the custom action.

For instance, suppose that the property attached to the Edit control is named MY_EDIT. Consider also that the custom action sets this property (MY_PROP) to the appropriate value. In this case the Execute custom action control event will be configured as follows:

  • Event Name: Execute custom action
  • Argument: Select the custom action that sets the MY_PROP property
  • Condition: 1

The Set installer property value control event will be configured as follows:

  • Event Name: [MY_EDIT]
  • Argument: [MY_PROP]
  • Condition: 1

NoteIf the Set installer property value control event is not defined, the property will be set correctly, but the edit control will not be updated until the user leaves the current dialog.

Warning!Due to a Windows Installer issue, the edit control will not be updated with the correct value if the user types in the Edit control before pressing the button. In order to avoid this issue you can use an Advanced Installer predefined custom action, as described below.

  • In the Custom Actions page add the "Update MSI edit controls" predefined custom action without sequence.
  • Add another Execute custom action published event to the button that modifies the edit control and make sure that this control event comes before the control events you specified above:
    • Event Name:Execute custom action
    • Argument: UpdateMsiEditControls
    • Condition: 1

NoteInstead of using a control event to invoke the UpdateMsiEditControls custom action, you could invoke it directly from your UI custom action

If you are using a C++ DLL Custom Action you would use:

MsiDoAction(hInstall, _T("UpdateMsiEditControls"));

In a VBScript custom action the code would be:

Session.DoAction("UpdateMsiEditControls")