XmlEvent.Validating event

Office 2013 and later

Occurs after changes to a form's underlying XML document have been accepted but before the Changed event has occurred.

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

public abstract event XmlValidatingEventHandler Validating


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


The developer attempted to add multiple delegates for the same XPath expression specifying a node or group. Only one delegate can be added for this event per XPath expression for a node or group.


The developer attempted to bind the event to a node in a secondary data source. This event is not supported for secondary data sources.

Important noteImportant

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

The Validating event is bound using the XmlValidatingEventHandler delegate.

This event handler does not allow users to cancel an operation.

During the Validate event, the form's underlying XML document is placed in read-only mode.

The Validate event is typically used for handling errors and working with the FormErrorCollection collection, for example, adding new errors or deleting existing ones.

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

In the following example, after a change has been accepted for field9, the Validating event is raised and a FormError object associated with field6 is added to the FormErrorCollection of the form using the Add method.

This associates an error message with field6. The string passed as the message parameter of the Add method is displayed in a screen tip when the user hovers over field6. When the user right-clicks field6 and then clicks Full error description, InfoPath displays the full error message including the string passed as the messageDetails parameter of the Add method.

public void field9_Validating(object sender, XmlValidatingEventArgs e)
   XPathNavigator errNode = 

   this.Errors.Add(errNode, "Field9Validating", 
      "Field9 was validated.", 
      "Field9 was validated and an error was assocated with Field6.");