Blog Stats
  • Posts - 79
  • Articles - 1
  • Comments - 30
  • Trackbacks - 191

 

Creating Modal Dialogs in InfoPath

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.


Feedback

# re: Creating Modal Dialogs in InfoPath

Gravatar I successfully created a modal dialog by using windows forms. My purpose was to be able to display a dialog that gets a userid and password and write them back to the infopath form's XML. (InfoPath has no password input type that does asterisks as you type so I was desperate for a solution).

In short, I just added a windows form to the InfoPath project. I added two textboxes (one as a password type) and a button.

Then in the code for the windows form, I added:

Imports Microsoft.Office.Interop.InfoPath.SemiTrust
Imports Microsoft.VisualBasic

I then modified its New() constructor to accept a ByRef argument of type XDocument (I bet you can see where this is going now).

So basically when I instantiate the form from the InfoPath event handler, I pass in the thisXDocument instance of XDocument.

For the button event handler on the windows form, I just grab the xmlnodes on the passed in xdocument that I'm interested in and write the text from the two textboxes to them. Since I passed in the infopath xdocument ByRef, the user id and password are actually written back to the original infopath form.

Cool! Email me if you got questions. 9/17/2004 6:21 PM | Tony (tprudente@biosite.com)

# re: Creating Modal Dialogs in InfoPath

Gravatar Tony said: "In short, I just added a windows form to the InfoPath project."

Wow. Can you do that? How?

11/30/2005 7:57 AM | Sparkplug

# re: Creating Modal Dialogs in InfoPath

Gravatar Hi!

I am preparing the infoPath forms for my company.

I have given button command by clicking the forms datas will go to back hand Access and through outlook it will go to next person.

Eg employee fills the form type the email of HOD and clicks the button so that matter goes to Access and form goes to the HOD inbox.

Now question is if HOD alters the matter of Employee and then futher sends to Finance Manager.....

i want that whosoever fills the form and sends to seniors the matter should become read only for others or it should ask for password to alter......

Your prompt reply will be highly appreciated.

REgards
Rupam sharma 1/31/2007 12:16 AM | Rupam Sharma

# hi..is it possible to create this form...?

Gravatar example: i create a leave form...example : with 2 user (Worker, Approver)

-Leave Form with 3 buttons ("Submit, Approve, Reject")

Submit button will be viewable to all, as for Approve Buttons / Reject Buttons, it will be only be viewable by Approver

then i upload it on the server, when a worker is to apply leave form that form,

Worker wont be able to see the Approve Buttons / Reject Buttons"Hidden", after Worker submit it...

When the Approver login in to Approve / Reject, he can only see the Approve Buttons / Reject Buttons "Shown"....

upon clicking the Approve Buttons / Reject Buttons, the Columns Display will update the Status ...

is it possible to create this type of form...?

thanks

with regards
...

if possible reply via email

satanic_workshiper@hotmail.com

thanks 2/26/2008 12:53 AM | jies

Post a comment





 

Please add 3 and 8 and type the answer here:

 

 

Copyright © Drew Robbins