Edit

Share via


XmlEvent.Validating Event

Definition

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

public:
 abstract event Microsoft::Office::InfoPath::XmlValidatingEventHandler ^ Validating;
public abstract event Microsoft.Office.InfoPath.XmlValidatingEventHandler Validating;
member this.Validating : Microsoft.Office.InfoPath.XmlValidatingEventHandler 
Public MustOverride Custom Event Validating As XmlValidatingEventHandler 

Event Type

Exceptions

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

Examples

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(XPathNavigator, String, String, String) 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.CreateNavigator().SelectSingleNode("/my:myFields/my:field6", 
      NamespaceManager);

   this.Errors.Add(errNode, "Field9Validating", 
      "Field9 was validated.", 
      "Field9 was validated and an error was assocated with Field6.");
}
Public Sub field9_Validating(ByVal sender As Object, _
   ByVal e As XmlValidatingEventArgs )
   Dim errNode As XPathNavigator = _
      Me.CreateNavigator().SelectSingleNode("/my:myFields/my:field6", _
      NamespaceManager)

   Me.Errors.Add(errNode, "Field9Validating", _
      "Field9 was validated.", _
      "Field9 was validated and an error was associated with Field6.")
End Sub

Remarks

Important: 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.

Applies to