Too Lazy to Switch Views - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Too Lazy to Switch Views

STATUS: Fixed in InfoPath 2003 SP1

DESCRIPTION:

While working on a project for Microsoft, Patrick Halstead and I were using some complex Open Rules and were having trouble getting things to work right. So, under the pressure of a deadline, we decided to convert them to code in the OnLoad event handler. It was during this process that we uncovered this bug on 2004-03-19 and reported it to our Microsoft contacts. It was at that point unknown to Microsoft. After this our only solution was to convert back to using Open Rules, which, as complex as they were, we eventually resolved our issues and get them to work as desired.

This bug is managed code specific, meaning it will not happen when using script. It is manifest when attempting to switch views in the OnLoad event handler, but only after the form has been cached locally.

The first time you run the form, when it has not yet been cached, the view will switch as expected, but there-after, until you clear the form from the InfoPath form cache, the view will fail to switch.

If you want see this happen, try this little experiment:

  1. Start Visual Studio.
  2. Create a new C# InfoPath Project, and name it ViewSwitchTest.
  3. In view 1, type the text View 1.
  4. Add a new view.
  5. In view 2, type the text View 2.
  6. In the Tools menu, select Programming | On Load Event.
  7. Enter the following line in the OnLoad event handler:

    thisXDocument.ViewInfos[1].IsDefault = true;


  8. Publish the form.
  9. Close InfoPath and Visual Studio.
  10. Open the form from the published location. It should open to view 2.
  11. Close InfoPath.
  12. Open the form again from the published location.

BUG: The form opens to view 1.

  1. Clear the form out of the InfoPath cache.
  2. Open the form from the published location. It should open to view 2.
  3. Close InfoPath.
  4. Open the form again from the published location.

BUG: The form opens to view 1.

This can be a very bad bug if the need arises for it. So what can be done? The workaround is to use Open Rules to do your view switching. If you have complicated code to figure out which view to switch to, this may not be a viable alternative. But fortunately, most view switching during the OnLoad stage will be able to be accomplished in the Open Rules.

©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Comments

No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.