How to: Display Alerts and Dialog Boxes Using the InfoPath 2003 Object Model

Office 2013 and later

Last modified: June 28, 2011

Applies to: InfoPath 2013 | InfoPath Forms Services | Office 2013 | SharePoint Server 2013

In this article
Overview of the UIObject Interface
Using the UIObject Interface
Using the ShowModalDialog Method

When writing code to extend the functionality of a form template that uses the InfoPath 2003 object model, it is often useful to provide the user with information in a dialog box. Programmatically displaying a dialog box and related user interface elements is accomplished in InfoPath by using the methods of the UIObject interface.

The UIObject interface provides the following methods, which form developers can use to have different types of dialog boxes displayed to InfoPath users as they are filling out a form.




Displays a simple message box that contains a specified message string. This method should be used when no input is required from the user and only a message needs to be displayed. The dialog box displayed is closed by clicking the OK button.


Displays a message box with buttons for input from a user. The value that is returned is one of the XdConfirmChoice enumerated constants.


Sets the default file name for a form in the Save As dialog box.


Sets the initial location at which the Save As dialog box starts to browse when it is opened.


Creates a new e-mail message in the default e-mail application, with the currently open form attached to the message.


Displays a modal dialog box, based on the specified .html file and positional arguments. This method should be used if you want to display more than a simple message to the user and you need to get back some data from the user (beyond the simple confirmation that is provided by the Yes | No | Cancel buttons displayed by the Confirm method).


Displays the built-in Digital Signatures dialog box.

The UIObject interface is accessed through the UI property of the XDocument interface, which itself is accessed through the thisXDocument variable that is initialized in the _Startup method of the form code class. The following example demonstrates using the ShowMailItem and Alert methods of the UIObject interface.

thisXDocument.UI.ShowMailItem("","", "", 
   "Updated Form", "Here is the updated form that you requested.");

thisXDocument.UI.Alert("The e-mail message has been created.");

This example demonstrates how to use the ShowModalDialog method of the UIObject interface to display a custom dialog box defined in the HTML file show.html.

public void CTRL1_5_OnClick(DocActionEvent e)
   // Write your code here.

Both the Visual C# and Visual Basic samples depend on an HTML file named "show.html" that defines the dialog box that is invoked by the ShowModalDialog method. This HTML file displays some data from the form and shows a text box for the user to fill in a value. The value in the textbox is returned to the form when the dialog box is closed.

      <script language="JScript">
function BtnClick()
   xdocument = window.dialogArguments;
   myXml = xdocument.DOM.xml
   aForm = oForm.elements;
   aForm.textBox.value = myXml;
      <H1><FONT face="Arial">This is a modal dialog box</FONT> &nbsp;
      <BUTTON onclick="BtnClick()" id="BUTTON1" type="button">
         Get XML DOM
      <FORM ID="oForm">
         <INPUT Type="text" name="textBox">

Important noteImportant

The ShowModalDialog method requires Full Trust to run or preview. For more information, see How to: Preview and Debug Form Templates that Require Full Trust.