Evento _XDocumentEventSink2_Event.OnLoad

Ocurre después de haber cargado un formulario de Microsoft InfoPath, pero antes de inicializar una vista.

Espacio de nombres:  Microsoft.Office.Interop.InfoPath.SemiTrust
Ensamblado:  Microsoft.Office.Interop.InfoPath.SemiTrust (en Microsoft.Office.Interop.InfoPath.SemiTrust.dll)

Sintaxis

'Declaración
Event OnLoad As _XDocumentEventSink2_OnLoadEventHandler
'Uso
Dim instance As _XDocumentEventSink2_Event
Dim handler As _XDocumentEventSink2_OnLoadEventHandler

AddHandler instance.OnLoad, handler
event _XDocumentEventSink2_OnLoadEventHandler OnLoad

Comentarios

Este controlador de eventos permite al usuario cancelar una operación.

Si la propiedad ReturnStatus del objeto DocReturnEventObject se establece como false, InfoPath cancela la carga del formulario. Si se produce un error en el código del evento OnLoad, InfoPath lo omite y se basa en la propiedad ReturnStatus. Si no se establece explícitamente la propiedad ReturnStatus, se usará el valor predeterminado: true.

Nota

Cuando ocurre el evento OnLoad, la vista no se inicializa y la transformación XSL (XSLT) utilizada para ella no se carga todavía. El objeto XDocument no se agrega a la colección XDocumentsCollection hasta que haya ocurrido el evento OnLoad. Sin embargo, el objeto XDocument estará disponible durante el evento OnLoad.

Importante

Este evento requiere un nivel de seguridad de confianza plena. Para establecer este nivel de seguridad, elija Opciones de formulario en el menú Herramientas de la ventana de diseño de InfoPath, a continuación, en la pestaña Seguridad seleccione Plena confianza. Debe haber un formulario de plena confianza instalado o firmado digitalmente.

Ejemplos

En el ejemplo siguiente, se utiliza el controlador de eventos OnLoad para determinar si el formulario se ha firmado digitalmente y, en caso negativo, inicializar algunos valores de datos utilizando una combinación de funciones y funciones personalizadas:

[InfoPathEventHandler(EventType=InfoPathEventType.OnLoad)]
public void OnLoad(DocReturnEvent e)
{ 
 // Avoid DOM updates when the document has been digitally signed.
 if (thisXDocument.IsSigned)
 {
  return;
 }

 string today = thisXDocument.Util.Date.Today().ToString();
 initializeNodeValue("/sls:salesReport/sls:date", today);
}

Este controlador de eventos Onload depende de dos funciones personalizadas: initializeNodeValue y setNodeValue.

private void initializeNodeValue(string xpath, string strValue)
{
 IXMLDOMNode xmlNode = thisXDocument.DOM.selectSingleNode(xpath);
 // Set the node value *ONLY* if the node is empty.
 if (xmlNode.text == "")
 {
  setNodeValue(xmlNode, strValue);
 }
}

private void setNodeValue(IXMLDOMNode xmlNode, string strValue)
{   
 if (xmlNode == null)
 {
  return;
 }

 // The xsi:nil needs to be removed before we set the value.
 if (strValue != "" && xmlNode.attributes.getNamedItem("xsi:nil") != null)
 {
  xmlNode.attributes.removeNamedItem("xsi:nil");
 }

 // Setting the value would mark the document as dirty.
 // Let's do that if the value has really changed.
 if (xmlNode.text != strValue)
 {
  xmlNode.text = strValue;
 }
}

Vea también

Referencia

interfaz _XDocumentEventSink2_Event

Miembros _XDocumentEventSink2_Event

Espacio de nombres Microsoft.Office.Interop.InfoPath.SemiTrust