Export (0) Print
Expand All

_DataDOMEventSink_Event.OnValidate Event (Microsoft.Office.Interop.InfoPath.SemiTrust)

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)

event _DataDOMEventSink_OnValidateEventHandler OnValidate

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.

NoteNote:

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.

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");
 }
}

Community Additions

ADD
Show:
© 2014 Microsoft