Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)
public abstract event LoadingEventHandler Loading
ExceptionCondition
InvalidOperationException

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

Important noteImportant

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 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.

NoteNote

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.

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"));
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.