_DataDOMEventSink_Event.OnValidate Event
Occurs after changes to a form's underlying XML document have been accepted but before the OnAfterChange event occurs.
Namespace: Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly: Microsoft.Office.Interop.InfoPath.SemiTrust (in Microsoft.Office.Interop.InfoPath.SemiTrust.dll)
Syntax
'Declaration
Event OnValidate As _DataDOMEventSink_OnValidateEventHandler
'Usage
Dim instance As _DataDOMEventSink_Event
Dim handler As _DataDOMEventSink_OnValidateEventHandler
AddHandler instance.OnValidate, handler
event _DataDOMEventSink_OnValidateEventHandler OnValidate
Remarks
This event handler does not allow users to cancel an operation.
During the OnValidate event, the form's underlying XML document is placed in read-only mode.
The OnValidate event is typically used for handling errors and working with the ErrorsCollection collection — for example, adding new errors or deleting existing ones.
Note
In some cases, events related to changes in a form's underlying XML document may occur more than once. For example, when existing data is changed, an insert and delete operation occurs.
Examples
In the following example, the Site property of the DataDOMEventObject object is used to check the value of the node. If the data validation fails, the ReportError method is used to create a custom error:
[InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.OnValidate)]
public void field1_OnValidate(DataDOMEvent e)
{
if (int.Parse(e.Site.text) > 50)
{
e.ReportError(
e.Site,
"Invalid quantity. The total number of each type of block cannot exceed 50.",
false,
"",
2,
"modeless");
}
if (int.Parse(e.Site.text) < 0)
{
e.ReportError(
e.Site,
"Invalid quantity. The total number of each type of block cannot be less than 0.",
false,
"",
2,
"modeless");
}
}
See Also
Reference
_DataDOMEventSink_Event Interface