Switch to read-only view on submit in InfoPath

Filed under: InfoPath 2007

Learn how you can use either rules or code to switch to a read-only view immediately after a form has been submitted.

ADVERTISEMENTS

In my previous post I wrote about how you can make controls on an InfoPath form read-only, and also about the advantages and disadvantages of using a read-only view.

A good example of a scenario in which you could consider using a read-only view is immediately after users submit an InfoPath form.

Scenario

You have an InfoPath form that has two views, one that is used to fill out data, and the other a read-only view that is only used to display the data that was filled out.

You want users to be able to click a Submit button to submit the InfoPath form to a SharePoint Form Library, and then immediately after the submit switch to the read-only view so that users can see the data that was submitted before closing the form.

Solution

You can use a rule or code to switch to a read-only view after submitting an InfoPath form.

Before you can complete the solution for this scenario, you have to create an InfoPath form that has 2 views named for example View 1 and View 2, a SharePoint submit data connection named SharePoint Library Submit, and a button control used for submitting the form.

In addition, you must make View 2 read-only (this is the view you’ll be switching to) and deselect the property Show on the View menu when filling out the form that is located on the General tab of the Properties dialog boxes of View 1 and View 2.

Use a rule to switch to a read-only view after submit

To use rules to submit an InfoPath form and then switch to a read-only view, you must add a Rule to the Submit button control on your InfoPath form template that has the following 2 Actions:

Submit using a data connection: SharePoint Library Submit

and

Switch to view: View 2

Use code to switch to a read-only view after submit

To use code to submit an InfoPath form and then switch to a read-only view, you must add the following C# code to the Clicked event handler of the Submit button control on your InfoPath form template:

DataConnections["SharePoint Library Submit"].Execute();
ViewInfos.SwitchView("View 2");

 


Related Posts

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.