FormEvents.Submit Event

Occurs when the Submit command is used from the user interface, or the Submit method is used.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in

Exception typeCondition


The developer attempted to bind the event in some location other than the InternalStartup method.


The Submit event is not meant to be instantiated by the developer in form code. You should only add event handlers for form-level events from the Microsoft Office InfoPath 2007 design mode user interface. When you add an event handler to your form template from the design mode user interface, InfoPath generates code in the InternalStartup method of your form code file using the EventManager class and the member of the FormEvents class to bind the event to its event handler. For information on how to add event handlers in InfoPath design mode, see How to: Add an Event Handler.

The Submit event is raised only if the form template has the Perform custom action using Code option set in the Submit Options dialog box.

The Submit event is bound using the SubmitEventHandler delegate.

The Submit event can be cancelled by using the CancelableArgs property of the MergeEventArgs class to set the Cancel property to true.

If event handler code uses the CancelableArgs property to set the strings of the Message or MessageDetails properties, but the CancelableArgs.Cancel property is left to the default setting of false, then a success message will be displayed with the text of the Message and MessageDetails properties. This message will override the Show a success or failure message and On success custom message settings in the Form Submit Options dialog box.

Similarly, if the event handler code sets the Message or MessageDetails strings, and sets CancelableArgs.Cancel to true, then a failure message will be shown, the message will be displayed with the text of the Message and MessageDetails properties, overriding the Form Submit Options dialog box settings.

If the event handler code leaves both Message and MessageDetails properties at the default value of null, but sets CancelableArgs.Cancel to true, then the submit operation is considered to have failed. Whether a failure message will be shown and what the message will be is determined by the settings in the Submit Options dialog box.

Calls to the Quit method of the Application class cannot be made in the Submit event handler.

This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.

In the following example, the event handler for the Submit event is used to prevent the form from being submitted if the form has not been saved.

public void FormEvents_Submit(object sender, SubmitEventArgs e)
   if(this.Dirty || this.New)
      MessageBox.Show("Please save this form before submitting it.");
      e.CancelableArgs.Cancel = true;
      e.CancelableArgs.Message = "Submit succeeded.";

Community Additions