次の方法で共有


_XDocumentEventSink2_Event.OnLoad イベント

定義

Microsoft InfoPath フォームが読み込まれた後、ビューが初期化される前に発生します。

public:
 event Microsoft::Office::Interop::InfoPath::SemiTrust::_XDocumentEventSink2_OnLoadEventHandler ^ OnLoad;
event Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_OnLoadEventHandler OnLoad;
member this.OnLoad : Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_OnLoadEventHandler 
Event OnLoad As _XDocumentEventSink2_OnLoadEventHandler 

イベントの種類

次の例では、OnLoad イベント ハンドラーを使用して、フォームがデジタル署名されているかどうかを確認し、まだ署名されていない場合は、あらかじめ用意されている関数とカスタム関数を併用して日付をいくつか初期化しています。

[InfoPathEventHandler(EventType=InfoPathEventType.<span class="label">OnLoad</span>)]
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);
}

この Onload イベント ハンドラーの例は、 と setNodeValueの 2 つのカスタム関数initializeNodeValueに依存します。

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 != "" &amp;&amp; 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;
 }
}

次の例では、OnLoad イベント ハンドラーを使用して、フォームがデジタル署名されているかどうかを確認し、まだ署名されていない場合は、あらかじめ用意されている関数とカスタム関数を併用して日付をいくつか初期化しています。

[InfoPathEventHandler(EventType=InfoPathEventType.<span class="label">OnLoad</span>)]
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);
}

この Onload イベント ハンドラーの例は、 と setNodeValueの 2 つのカスタム関数initializeNodeValueに依存します。

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 != "" &amp;&amp; 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;
 }
}

注釈

このイベント ハンドラーでは、ユーザーが操作を取り消せます。

オブジェクトの ReturnStatus プロパティが DocReturnEventObjectfalse に設定されている場合、InfoPath はフォームの読み込みを取り消します。 OnLoad イベントに関するコードでエラーが発生した場合は、そのエラーが無視され、ReturnStatus プロパティに応じて処理が実行されます。 ReturnStatus プロパティが明示的に設定されていない場合は、既定値 true が使用されます。

: OnLoad イベントが発生すると、ビューは初期化されず、ビューに使用される XSL 変換 (XSLT) はまだ読み込まれません。 XDocumentOnLoad イベントが発生するまで、オブジェクトはコレクションに追加XDocumentsCollectionされません。 ただし、XDocument オブジェクトは OnLoad イベントの発生中でも使用できます。

重要: このイベントには、完全信頼セキュリティ レベルが必要です。 このセキュリティ レベルを設定するには、InfoPath デザイン ウィンドウで [ツール] メニューの [フォームのオプション] をクリックし、[セキュリティ] タブの [完全信頼] をクリックします。 あらかじめ完全信頼フォームをインストールまたはデジタル署名しておく必要があります。

適用対象