Compartir a través de


FormEvents.Loading Event

Occurs when the form template has been loaded, but before any views have been initialized.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustOverride Event Loading As LoadingEventHandler
'Usage
Dim instance As FormEvents
Dim handler As LoadingEventHandler

AddHandler instance.Loading, handler
public abstract event LoadingEventHandler Loading

Exceptions

Exception Condition
InvalidOperationException

The developer attempted to bind the event in some location other than the InternalStartup method.

Remarks

Important

The Loading event is not meant to be instantiated by the developer in form code. You should only add event handlers for form-level events from the Microsoft InfoPath 2010 design mode user interface. When you add an event handler to your form template from the design mode user interface, InfoPath generates code in the InternalStartup method of your form code file using the EventManager class and the member of the FormEvents class to bind the event to its event handler. For information on how to add event handlers in InfoPath design mode, see How to: Add an Event Handler.

The Loading event is bound using the LoadingEventHandler delegate.

The Loading event occurs before the form is loaded and before the view is rendered.

If a form template is deployed to and opened from an appropriately configured document library on SharePoint Server 2010 running InfoPath Forms Services, the Loading event only occurs once per session.

The Loading event can be cancelled by using the CancelableArgs property of the SaveEventArgs class to set the Cancel property to true.

Note

When the Loading event occurs, the view is not initialized and the XSL Transformation (XSLT) used for the view is not yet loaded. The XmlForm object is not added to the XmlFormCollection collection until after the Loading event has occurred. However, the XmlForm object is available during the Loading event.

Calls to the following methods and properties cannot be made in the Loading event handler:

Quit

DisableAutoUpdate

EnableAutoUpdate

ExecuteAction

Export

ForceUpdate

GetContextNodes

GetSelectedNodes

SelectNodes

SelectText

SwitchView

Close

MergeForm

New

Save

SaveAs

Submit

Print

NewFromFormTemplate

Close

TaskPanes

Calls to the members of the AdoSubmitConnection, EmailSubmitConnection, or FileSubmitConnection classes cannot be made in the Loading event handler.

This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

Examples

In the following example, the event handler for the Loading event is used to determine whether the form has been digitally signed, and if it hasn't sets the Date1 field to the current date.

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
   if (this.Signed)
   {
         e.CancelableArgs.Message = 
            "This form is digitally signed. Loading is cancelled.";
         e.CancelableArgs.Cancel = true;
   }

   XPathNavigator myDate = 
      CreateNavigator().SelectSingleNode("/my:myFields/my:date1",
      NamespaceManager);

   // Check for and delete xsi:nil="true" attribute.
   if (myDate.MoveToAttribute("nil", 
      "http://www.w3.org/2001/XMLSchema-instance"))
   {
      myDate.DeleteSelf();
   }

   myDate.SetValue(System.DateTime.Now.ToString("yyyy-MM-dd"));
}
Public Sub FormEvents_Loading(ByVal sender As Object, _
   ByVal e As LoadingEventArgs)
   If (Me.Signed)Then
         e.CancelableArgs.Message = 
            "This form is digitally signed. Loading is cancelled."
         e.CancelableArgs.Cancel = True
   End If

   Dim myDate As XPathNavigator = 
      CreateNavigator().SelectSingleNode("/my:myFields/my:date1",
      NamespaceManager)

   ' Check for and delete xsi:nil="true" attribute.
   If (myDate.MoveToAttribute("nil", 
      "http://www.w3.org/2001/XMLSchema-instance"))
      myDate.DeleteSelf();
   End If

   myDate.SetValue(System.DateTime.Now.ToString("yyyy-MM-dd"));
End Sub

See Also

Reference

FormEvents Class

FormEvents Members

Microsoft.Office.InfoPath Namespace