XmlEvent.Validating Event
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)
Syntax
'Declaration
Public MustOverride Event Validating As XmlValidatingEventHandler
'Usage
Dim instance As XmlEvent
Dim handler As XmlValidatingEventHandler
AddHandler instance.Validating, handler
public abstract event XmlValidatingEventHandler Validating
Exceptions
Exception | Condition |
---|---|
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. |
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 2010 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.
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 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