Geeks With Blogs
Drewby Made from 60% post-consumer recycled fiber.
A couple days ago, I wrote about the ability to create a Custom Task Pane in InfoPath. You can use a similar technique to show modal dialogs based on an HTML file. The UI object has a method called ShowModalDialog that takes an HTML file as a parameter as well as a variant argument to pass to the dialog. Most likely, you'll pass the XDocument object as the argument.

By passing the XDocument as an argument, the HTML file can make use of the InfoPath OM and the DOM to manipulate the form and document as well as run methods in the code-behind file. The primary and secondary data sources are also available to the HTML file.

Create an HTML file using your favorite editor. Include controls for the user to query a web service or whatever functionality you want to provide. Add this HTML file as a resource in the form (Tools | Form Options | Advanced).

To show the dialog, create an event handler in the code-behind script that is attached to an action such as the click event on a button. Call the following method in the event handler:

function MyButton::OnClick
{
    XDocument.UI.ShowModalDialog("MyDialog.htm", XDocument, 300, 450);
}

This will launch MyDialog.htm file in a 300x340 modal dialog and pass the XDocument as an argument. To use the XDocument from the script in the HTML file, use the dialogArguments property of the window object:

var xDocument = window.dialogArguments;
Why go through all this trouble? Well, the controls on the InfoPath form must be bound to an element in your XML document. So, if there are tasks that you want to implement that are not directly related to an element in your XML document, you can use the Custom Task Pane or a modal Dialog to implement the functionality.

You could also use a managed component and a Windows Forms dialog, but that's for another post on another day.

Posted on Friday, January 16, 2004 8:52 PM Office | Back to top

Copyright © Drew Robbins | Powered by: GeeksWithBlogs.net