Edit

Share via


_DataDOMEventSink_Event.OnValidate Event

Definition

Occurs after changes to a form's underlying XML document have been accepted but before the OnAfterChange event occurs.

public:
 event Microsoft::Office::Interop::InfoPath::SemiTrust::_DataDOMEventSink_OnValidateEventHandler ^ OnValidate;
event Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_OnValidateEventHandler OnValidate;
member this.OnValidate : Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_OnValidateEventHandler 
Event OnValidate As _DataDOMEventSink_OnValidateEventHandler 

Event Type

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(Object, String, Boolean, String, Int32, String) method is used to create a custom error:

[InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.<span class="label">OnValidate</span>)]
public void field1_<span class="label">OnValidate</span>(DataDOMEvent e)
{
 if (int.Parse(e.Site.text) &gt; 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) &lt; 0)
 {
  e.ReportError(
   e.Site, 
   "Invalid quantity. The total number of each type of block cannot be less than 0.", 
   false,
   "",
   2,
   "modeless");
 }
}

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(Object, String, Boolean, String, Int32, String) method is used to create a custom error:

[InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.<span class="label">OnValidate</span>)]
public void field1_<span class="label">OnValidate</span>(DataDOMEvent e)
{
 if (int.Parse(e.Site.text) &gt; 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) &lt; 0)
 {
  e.ReportError(
   e.Site, 
   "Invalid quantity. The total number of each type of block cannot be less than 0.", 
   false,
   "",
   2,
   "modeless");
 }
}

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.

Applies to