FormState["_memberVariable"] = Class - InfoPath Dev
in

InfoPath Dev

FormState["_memberVariable"] = Class

Last post 07-21-2009 11:07 PM by Jimmy. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 12-13-2006 05:08 AM

    • Kun
    • Not Ranked
    • Joined on 11-07-2006
    • Posts 13

    FormState["_memberVariable"] = Class

    Is it just possible to store elementary data types in FormState[]? I want to do something like that:


    private SPListItemCollection _memberVariable
    {
    get
    {
    return FormState["_memberVariable"] as SPListItemCollection;
    }
    set
    {
    FormState["_memberVariable"] = value;
    }
    }


    and access it:


    _memberVariable = list.GetItems(query);


    Then I get the following exception:


    System.Runtime.Serialization.SerializationException was unhandled by user code
    Message="Serialization error."
    Source="Microsoft.Office.InfoPath.Client.Internal.Host"
    StackTrace:
    at Microsoft.Office.InfoPath.Internal.FormStateBagHost.System.Collections.IDictionary.set_Item(Object key, Object value)
    at CommunicationSet.FormCode.set__memberVariable(SPListItemCollection value) in (...)
    Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
  • 12-14-2006 07:40 AM In reply to

    Re: FormState["_memberVariable"] = Class

    Hi Kun,

    I'm confused by this code - are you writing this in codebehind an InfoPath form or is this a SharePoint web part? Can you give us some context here?
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-14-2006 08:15 AM In reply to

    • Kun
    • Not Ranked
    • Joined on 11-07-2006
    • Posts 13

    Re: FormState["_memberVariable"] = Class

    quote:
    are you writing this in codebehind an InfoPath form or is this a SharePoint web part? Can you give us some context here?



    It's a codebehind file, "FormCode.cs", VSTA. Not a webpart! Does this help?
  • 11-21-2007 04:50 AM In reply to

    Re: FormState["_memberVariable"] = Class

    You can store any objects in FormState as long as they are serializable. To mark a class as serializable you can add the [System.SerializableAttribute()] to your class definition.

    In your case this will not work because SPListItemCollection is already not serializable. One approach here would be to re-create it every time the business logic is called.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-21-2009 04:18 AM In reply to

    • Scroll
    • Not Ranked
    • Joined on 05-25-2009
    • Posts 7

    Re: FormState["_memberVariable"] = Class

    Hi!
    I have code:
    private XPathNavigator mRoot
    {
    get{return (XPathNavigator)FormState["mRoot"];}
    set { FormState["mRoot"] = value; }
    }

    XPathNavigator is not serializable. How I can use this class in FormState? If I can't use it then how I can create global XPathNavigator variable in browser-enabled form?
  • 07-21-2009 07:00 AM In reply to

    Re: FormState["_memberVariable"] = Class

     I don't work with browser-enabled forms so I've never used the form state, but could you tell us why you want to store an XPathNavigator globally?  I can't think of a whole lot of reasons why you would need to.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-21-2009 09:04 PM In reply to

    • Scroll
    • Not Ranked
    • Joined on 05-25-2009
    • Posts 7

    Re: FormState["_memberVariable"] = Class

    Course, I can store XPathNavigator locally (So I did now), but it is inconvenient. I need for each function to create a new variable.
  • 07-21-2009 11:07 PM In reply to

    Re: FormState["_memberVariable"] = Class

    I'm not sure why it has to be inconvenient.  You could do something like:

    private XPathNavigator m_mRoot;
    private XPathNavigator mRoot
    {
         get
         {
              if(m_mRoot == null)
              {
                   m_mRoot = // insert logic to produce mRoot
              }
              return m_mRoot;
         }
    }

    That will work if mRoot is always supposed to be pointing to the same spot.  Will that work?

    That should be easy enough to use.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.