Compartir a través de


_DataDOMEventSink_Event.OnValidate Evento

Definición

Se produce después de que se hayan aceptado los cambios en el documento XML subyacente de un formulario, pero antes de que se produzca el OnAfterChange evento.

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 

Tipo de evento

Ejemplos

En el ejemplo siguiente, se usa la SiteDataDOMEventObject propiedad del objeto para comprobar el valor del nodo. Si se produce un error en la validación de datos, se usa el ReportError(Object, String, Boolean, String, Int32, String) método para crear un error personalizado:

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

En el ejemplo siguiente, se usa la SiteDataDOMEventObject propiedad del objeto para comprobar el valor del nodo. Si se produce un error en la validación de datos, se usa el ReportError(Object, String, Boolean, String, Int32, String) método para crear un error personalizado:

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

Comentarios

Este controlador de eventos no permite a los usuarios cancelar una operación.

Durante el evento OnValidate, el documento XML subyacente del formulario se pone en modo de sólo lectura.

El evento OnValidate se usa normalmente para controlar errores y trabajar con la ErrorsCollection colección, por ejemplo, agregar nuevos errores o eliminar los existentes.

Nota: En algunos casos, los eventos relacionados con los cambios en el documento XML subyacente de un formulario pueden producirse más de una vez. Por ejemplo, cuando se cambian los datos existentes, tiene lugar una operación de inserción y eliminación.

Se aplica a