UI.ShowModalDialog Method

InfoPath Developer Reference

Displays a custom modal dialog box in a Microsoft Office InfoPath 2007 form.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.ShowModalDialog(bstrName, varArguments, varHeight, varWidth, varTop, varLeft)

expression   An expression that returns a UI object.

Parameters

Name Required/Optional Data Type Description
bstrName Required String The name of the .html file used for the modal dialog box.
varArguments Optional Variant Specifies the arguments to use when displaying the modal dialog box. Can be any type of value, including an array of values.
varHeight Optional Variant Sets the height of the modal dialog box.
varWidth Optional Variant Sets the width of the modal dialog box.
varTop Optional Variant Sets the top position of the modal dialog box relative to the upper left corner of the desktop.
varLeft Optional Variant Sets the left position of the modal dialog box relative to the upper left corner of the desktop.

Return Value
Variant

Remarks

The ShowModalDialog method of the UI object allows you to display custom dialog boxes to users as they fill out a fully trusted form. Custom dialog boxes are implemented as .html files created in any type of HTML editor. You can use scripting code in a custom dialog box that interacts with the InfoPath object model if you pass objects to the custom dialog box using the

varArguments

parameter.

To use a custom dialog box in an InfoPath form, you must first add the .html file of the custom dialog box to the form's set of resource files by using the Resource Manager dialog box. The Resource Manager dialog box is available from the Tools menu in design mode. After you have added the custom dialog box file to the form, you can use the ShowModalDialog method to display it.

Bb229821.vs_note(en-us,office.12).gif  Note
Although the ShowModalDialog method can only be used in fully trusted forms, you can create a custom dialog box in standard forms using the showModalDialog method of the Dynamic HTML (DHTML) object model.

Security Level 3: Can be accessed only by fully trusted forms.

Example

In the following example, the ShowModalDialog method of the UI object is used to display a custom dialog box. Note that the XDocument object is passed to the custom dialog box using the varArguments parameter.

JScript
  XDocument.UI.ShowModalDialog("SimpleDialog.htm", XDocument);

The following example is the HTML code used to implement a simple custom dialog box. Note the use of the dialogArguments property of the DHTML window object to get the values passed to the custom dialog box, which in this case is the XDocument object of the InfoPath object model, from the ShowModalDialog method. When a user clicks the Show Alert button in the custom dialog box, the source XML of the form's underlying XML document appears in a message box.

JScript
  <html>
   <head>
      <script language="jscript">
         var gobjXDocument = null;
     function Initialize()
     {
        // Save a reference to the XDocument object.
        if (typeof window.dialogArguments == "object")
        gobjXDocument = window.dialogArguments;
     }
  &lt;/script&gt;

  &lt;title&gt;A Simple Custom Dialog Box&lt;/title&gt;

</head>

<body style="BACKGROUND-COLOR: window" onLoad="Initialize()"> <strong>Click one of the following buttons:</strong> <br/> <br/> <div id="divButtons" tyle="align:center"> <input id="btnShowAlert" style="WIDTH: 106px; HEIGHT: 24px" onclick='gobjXDocument.UI.Alert(gobjXDocument.DOM.xml);' type="button" size="21" value="Show Alert"></input> <input id="btnCancel" style="WIDTH: 106px; HEIGHT: 24px" onclick="window.close();" type="button" size="21" value="Cancel"></input> </div> </body> </html>

See Also