Hello,
The code to reproduce the problem is quite simple:
1) Create a InfoPath 2007 form with browser compatibility
2) Add a button "Button1" with custom code that executes this.Submit();
3) Configure the Form Submit Options to submit the form using custom code that does nothing:
public void Button1_Clicked(object sender, ClickedEventArgs e)
{
this.Submit();
}
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
e.CancelableArgs.Cancel = false; // Success
}
4) Publish the form to a MOSS Form library (admin approval with the Central Administration)
When you open the form on a browser and you click the button, you get an error like "Can't call XmlForm.Submit from SubmitEventHandler" (or similar, I have translated it from Spanish to English).
I think that the problem happens because InfoPath or InfoPath Forms Services thinks that the Button1_Clicked method is a SubmitEventHandler, when it is not. The call to XmlForm.Submit it is not in a submit event handler, it is in a button click event handler, which is different. In my view this is a bug of the product.
Using the click event of the button to call the same code that is in the "Submit" event and remove the Submit event handler is not a solution for me since I want to:
a) When the button is clicked, perform some actions before submitting the form. I have actually several buttons ("Approve", "Reject", etc) so each button has its own code.
b) Submit the form if the actions are ok
c) Close the form. According to this, it must be done through the "Form Submit Options", "Advanced", "Close the form" option:
How to execute code and close an InfoPath web-based form
http://www.bizsupportonline.net/blog/2009/01/how-to-programmatically-run-code-close-infopath-web-form/