A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Sunday, November 9, 2008

Preserve code blocks are not supported in browser-enabled InfoPath forms

Preserve code blocks are not supported in browser-enabled InfoPath forms

The text on the button can be changed dynamically in InfoPath 2007. If you bind the button to a data source and then change the value of the data source using rules, the value of the button text will change dynamically. Can this be done programmatically? Yes! You can modify the XSL of the view to control the text of the button but the problem is this has to be done manually and when you load the view in editor, all your changes are lost. To preserve your changes, you must use "xd:preserve" but the problem is "xd:preserve" or "Preserve Code Block" is not supported in browser-enabled InfoPath forms. It will work in InfoPath client though. If you have no clue what I am talking about, then read the following article:

Using Custom XSLT in InfoPath Form Templates

This question is usually asked in forums where people ask if they can change the button text/label programmatically. As I mentioned above, the answer is "Yes" but it will be very difficult to manage the XSL if you cannot preserve your changes. Every time you want to publish your form, you will have to re-do your changes in the XSL. The following MSDN article clearly mentions that "xd:preserve" blocks are not supported in Forms services:

Creating InfoPath Form Templates That Work With Forms Services

After changing the XSL, you will see a red box on your form in the design mode with text "Preserve Code Block".



If you have enabled browser compatibility in your form, then the design checker will show the error:



"Preserve code blocks (xd:preserve) are not supported".

Click the error message, javascript pop-up will appear:



If you still want to go ahead and make changes in your XSL, remove the template block and save the changes outside InfoPath. Publish the form and your changes will work fine. In next article, I will show you how you can control the button text dynamically. It should have been other way round. I should have written about controlling button text first but anyway, doesn't make any difference.

No comments:

Post a Comment