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 Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustOverride Event Submit As SubmitEventHandler
'Usage
Dim instance As FormEvents
Dim handler As SubmitEventHandler

AddHandler instance.Submit, handler
public abstract event SubmitEventHandler Submit

Exceptions

Exception Condition
InvalidOperationException

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

Remarks

Important

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 InfoPath 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 a null reference (Nothing in Visual Basic), 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 InfoPath Filler or in a Web browser.

Examples

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;
   else
      e.CancelableArgs.Message = "Submit succeeded.";
}
Public Sub FormEvents_Submit(ByVal sender As Object, _
   ByVal e As SubmitEventArgs)
   If(Me.Dirty Or Me.New) Then
      MessageBox.Show("Please save this form before submitting it.")
      e.CancelableArgs.Cancel = True
   Else
      e.CancelableArgs.Message = "Submit succeeded."
   End If
End Sub

See also

Reference

FormEvents class

FormEvents members

Microsoft.Office.InfoPath namespace