Error Can't call XmlForm.Submit from SubmitEventHandler - InfoPath Dev
in

InfoPath Dev

Error Can't call XmlForm.Submit from SubmitEventHandler

Last post 12-07-2009 07:59 AM by carlosq. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11-30-2009 04:41 AM

    Error Can't call XmlForm.Submit from SubmitEventHandler

    Hello,

    I have a web-based form (InfoPath Forms Services) and InfoPath 2007. In my form:

     - I have a button with the action "Rules and custom code", and in the custom code (click event handler) I perform some validations and I call this.Submit()

    - The Form Submit Options are configured to use custom code (FormEvents_Submit event handler). The code calls the Execute method of a connection.

    When I try this approach in the preview, it works fine, but when the form is hosted in InfoPath Forms Services, I get this error:

     "Can't call XmlForm.Submit from SubmitEventHandler" (or similar, it is a translation from Spanish)

    I don't understand why is this happening since the Click event handler of the button  (that calls XmlForm.Submit) is not a SubmitEventHandler (the method FormEvents_Submit is) , it is the click event handler of a button.

    Any ideas? Is it a bug?

    I am using this approach because I have to use several buttons to submit the form with different meanings and validations, and I want the form closed after submit, something that seems to be possible only using  Form Submit Options with the advanced option of closing the form.

  • 12-04-2009 03:07 PM In reply to

    Re: Error Can't call XmlForm.Submit from SubmitEventHandler

    Someone commenting on an InfoPath Team Blog post had the same issue at one point. The blog post is here, and the comment is about a third of the way down.

    The person who replied to the comment suggest:

    - Use the click event of the button to call the same code that is in the "Submit" event and remove the Submit event handler.

    NOTE: ... you will  need to remove the "e.CancelableArgs" lines.

    You may also want to try posting your code here, in case someone can see what might be wrong.

    Hilary Stoupa

  • 12-07-2009 07:59 AM In reply to

    Re: Error Can't call XmlForm.Submit from SubmitEventHandler

    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/

     

     

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.