I have a browser based InfoPath form on which I have a button that when clicked runs some C# code behind it to do various routines like some validation, adding rows to repeating tables and submitting the form. All of this works as expected, however I also need the form to close after the submit. I have spent two days trying all sorts of options, none of which work. Surely there is a way to accomplish this, I just need someone who is more adept at InfoPath to point it out for me?
Thank you in advance for your assistance.
- Edited by JaeEmAre Friday, November 13, 2009 1:28 PM No longer needed
you can do this in 2 ways.
1. As Madura said adda rule ( get button properties -> add rules -> add action -> select "Close the form")
2. In FormEvents_Loading method get the url of the previous page
redirectURL = HttpContext.Current.Request.UrlReferrer.OriginalString.ToString();
and in the button Clicked method
but i am not able to write this code bcz it give build error
string edirectURL = HttpContext.Current.Request.UrlReferrer.OriginalString.ToString();
Error 2 The name 'HttpContext' does not exist in the current context F:\Projects\Current Projects\Eicher\CodefileofIDPR\Appraisal\FormCode.cs 94 36 Appraisal
may i have to add any extra name space
Yes because you have to add namespace "using System.Web" in your code.
The name "httpcontext" comes under this namespace only.
and one more thing you have to do is, use System.Web.UI.Page with your partial class ..........
public partial class FormCode : System.Web.UI.Page
I think Madhur Ahuja is on the right path. I faced a similar question and did it this way.
Set the Submit Option to "Perform custion action via Code", and set the Advanced "After Submit" property to "Close the Form"
Code the FormEvents_Submit . For the submit to the form library to work you need to use the FileSubmitConnection related code.
Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)
' If the submit operation is successful, set e.CancelableArgs.Cancel = False
' Write your code here.
Dim lb_Success As Boolean = False
Dim fc As FileSubmitConnection
fc = DirectCast(Me.DataConnections("SharePoint Library Submit"), FileSubmitConnection)
e.CancelableArgs.Cancel = False 'success
lb_Success = True
Catch ex As Exception
e.CancelableArgs.Cancel = True 'Error
of_ErrorMessageFunction("Error Submiting the form - FC Execute Error: " + ex.Message, False)
If lb_Success Then
' any other non-critical processing
fc = Nothing
3. Finally, add a button with the Action property set to Submit, which will use your code.
hi actually i tried with this same things with programming but i can't . Thats why i do something different .
As i create a view with button to close. And after my code complete just switch the view .
And u can also add a rule to close the form .It auto matically close the form but validation can't be checked
it fine i use this its fine, but problem i face code is
if (MainNav.SelectSingleNode("/my:myFields/my:field1", NamespaceManager).ToString().Contains("P") == true)
e.CancelableArgs.Cancel = false;
e.CancelableArgs.Cancel = true;
but when the condition get false then it give an Warning message as i place the code in try and catch block.
i don't want to show the warning message..
Warning message is
There has been an error while processing the form. Click Continue to resume filling out the form. You may want to check your form data for errors. Click Start Over to load a new copy of the form. Hide error detailsxxx
Thanks and Regards Er.Pradipta Nayak
I used your solution but it didn't work , this is my code:
public partial class FormCode:System.Web.UI.Page
- after using inheritance this error occured :
Error 1 Missing partial modifier on declaration of type 'SubmitTemplate.FormCode'; another partial declaration of this type exists ....\InfoPath Projects\SubmitTemplate1\FormCode.cs 8 26 SubmitTemplate
- without using inheritance i got "object reference error".
i add system.web as refrences too.and my form is brwser-enabled .could you help me to solve this ?
,I have a button in form and i handle click event for that (in code) to save in My sharepoint Document Library.(it works well)
so after saving without error, i want to close form (i cannot use a Close Rule for that , because it occurs before click event)
or redirect it to Document Library (this part is the problem ),
I should add my form is browser enabled, too. and jscript it's not work
although i test thease code too, and did not work when i publish form to sharepoint :
please help me how i can solve it?