Saturday, May 22, 2010

Using this.Submit to close InfoPath form

Lately I was working on a InfoPath form.  I thought that it will be nice if I can validate the form with custom code and also close it.  I didn't liked the Submit button event handler as it was displaying its own pop dialog box before showing my custom error messages.  I added my own button I tried to use this.Submit() method to execute Submit form option for closing the form, as we know that you cannot call "Close form" from your code.  On form Submit option using "Perform custom action using code" I end up gettting this exception

XmlForm.Submit cannot be called from the SubmitEventHandler.

Finally I figured out that if I use "Perform custom action using rule" on Form Submit options dialog box then from custom button action event handler I can call this.Submit() and it allow for me allowing me to close the form by calling form Submit option - "Close the form".

In case anyone of you interested in how its done here is my project and xsn file -

http://cid-cb9fe32f865358ac.skydrive.live.com/browse.aspx/Public/Submit?lc=1033

also here are some of settings that I had in my form -

On the rule dialog box I just set a temp field to 1,



I hope this will be usefull to those who want to submit and close the form on the same page using code without adding extra view/page to close the form.


Thanks,
Suhaib Khan

No comments:

Post a Comment