Another day, another weird InfoPath problem...
So, I'm building custom ActiveX controls in C# by following these tutorials - mhttp://blogs.msdn.com/b/infopath/archive/2006/12/18/creating-complex-infopath-controls-in-c-sharp.aspx and http://blogs.msdn.com/b/infopath/archive/2005/04/15/creating-an-infopath-custom-control-using-c-and-net.aspx. Generally things are straightforward and I have working controls that can return simple values, xml, etc.
However, one thing asserted in the msdn posts is that InfoPath will repeatedly destroy and reinstantiate controls as the view is updated - and so you cannot store state in the control. I was surprised, then, to see that in InfoPath 2010, I absolutely can store state (fields, properties, .NET controls) in the control, and save it to xml when the form is submitted. Event stranger, putting a MessageBox.Show() in the control constructor indicates that the control is being repeatedly reinstantiated, but only one version is accessible to the user. I am somewhat troubled by this as I'm not sure why extra copies of the control are being instantiated, and this could cause a serious performance problem if the controls become complex
So, now I try it out in InfoPath 2007, and I find that the ActiveX control is indeed being destroyed and reinstantiated (destroying all state) every time the data changes. This basically means that all state will need to be stored somewhere (probably the form xml) to repopulate the control when it is refreshed.
This is obviously a pretty major difference between InfoPath 2007/2010 - but I can find no documentation, or any other mention, of the phenomenon. The articles cited above are pretty old and so correctly refer to the behavior of 2007. If anybody can shed any light on this I'd be very grateful!