Disable/Ignore C# Form Loading Event - InfoPath Dev
in

InfoPath Dev

Disable/Ignore C# Form Loading Event

Last post 07-31-2013 06:21 AM by Big E. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-30-2013 11:18 AM

    • Big E
    • Top 500 Contributor
      Male
    • Joined on 02-18-2009
    • Alabama
    • Posts 35

    Disable/Ignore C# Form Loading Event

    I have a form that performs a specific task on form load.  This is working properly.  My question is, how do I disable/ignore this form load if I'm trying to open a submitted form.  I only need to run the below code on creation.

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;

    namespace WorkOrder
    {
        public partial class FormCode
        {
            // Member variables are not supported in browser-enabled forms.
            // Instead, write and read these values from the FormState
            // dictionary using code such as the following:
            //
            // private object _memberVariable
            // {
            //     get
            //     {
            //         return FormState["_memberVariable"];
            //     }
            //     set
            //     {
            //         FormState["_memberVariable"] = value;
            //     }
            // }

            // NOTE: The following procedure is required by Microsoft InfoPath.
            // It can be modified using Microsoft InfoPath.
            public void InternalStartup()
            {
                EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
            }

            public void FormEvents_Loading(object sender, LoadingEventArgs e)
                {
                // Be sure that the InputParameter dictionary contains
                // values before proceeding.
                bool FormEvents_Loading;
                if (e.InputParameters.Count != 0)
                {
                    string vDate = e.InputParameters["Date"];
                    string vCont = e.InputParameters["Cont"];
                   
                    XPathNavigator myNav = CreateNavigator();
                    myNav.SelectSingleNode("/my:myFields/my:Reps/my:Contractor",NamespaceManager).SetValue(vCont);
                    myNav.SelectSingleNode("/my:myFields/my:Service/my:Date", NamespaceManager).SetValue(vDate);
                }
            }
        }
    }

     

  • 07-30-2013 07:13 PM In reply to

    Re: Disable/Ignore C# Form Loading Event

    Here's one simple thing you could do:

      public void FormEvents_Loading(object sender, LoadingEventArgs e)
                {
                // Be sure that the InputParameter dictionary contains
                // values before proceeding.
                bool FormEvents_Loading;

                if(this.New){
                  if (e.InputParameters.Count != 0)
                  {
                    string vDate = e.InputParameters["Date"];
                    string vCont = e.InputParameters["Cont"];
                   
                    XPathNavigator myNav = CreateNavigator();
                    myNav.SelectSingleNode("/my:myFields/my:Reps/my:Contractor",NamespaceManager).SetValue(vCont);
                    myNav.SelectSingleNode("/my:myFields/my:Service/my:Date", NamespaceManager).SetValue(vDate);
                  }
               }
            }

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-31-2013 06:21 AM In reply to

    • Big E
    • Top 500 Contributor
      Male
    • Joined on 02-18-2009
    • Alabama
    • Posts 35

    Re: Disable/Ignore C# Form Loading Event

    Thanks Jimmy.  That worked great!
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.