Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

XmlEvent.Validating Event (Microsoft.Office.InfoPath)

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
Exception typeCondition

InvalidOperationException

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

InvalidOperationException

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.

InvalidOperationException

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

ImportantImportant:

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 Office InfoPath 2007 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 Office InfoPath 2007 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.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.");
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.