protected void Page_Load(object sender, EventArgs e)
        {
            //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            //InitializedSfdcbinding();

            if ((String)Session["AccountId"] != null)
            {
                strAccountId = (String)Session["AccountId"];
            }

            if ((String)Session["Email"] != null)
            {
                strEmail = (String)Session["Email"];
            }

            if ((String)Session["ContactId"] != null)
            {
                strPrimaryContactId = (String)Session["ContactId"];
            }
            else
            {
                String strQueryForPrimaryContactId = "select Id from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                                     "and cmm_Household_Role__c = 'Head of Household'";

                SForce.QueryResult qrPrimaryContactId = Sfdcbinding.query(strQueryForPrimaryContactId);

                if (qrPrimaryContactId.size > 0)
                {
                    SForce.Contact ctPrimaryContactId = qrPrimaryContactId.records[0] as SForce.Contact;

                    strPrimaryContactId = ctPrimaryContactId.Id;
                }
            }
            if ((String)Session["SpouseId"] != null)
            {
                strSpouseId = (String)Session["SpouseId"];
            }
            else
            {
                String strQueryForSpouseId = "select Id from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                             "and cmm_Household_Role__c = 'Spouse'";

                SForce.QueryResult qrSpouseId = Sfdcbinding.query(strQueryForSpouseId);

                if (qrSpouseId.size > 0)
                {
                    SForce.Contact ctSpouseId = qrSpouseId.records[0] as SForce.Contact;

                    strSpouseId = ctSpouseId.Id;
                }
            }

            String strQueryForChildrenId = "select Id from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                           "and cmm_Household_Role__c = 'Child'";

            SForce.QueryResult qrChildrenId = Sfdcbinding.query(strQueryForChildrenId);

            if (qrChildrenId.size > 0)
            {
                for (int i = 0; i < qrChildrenId.size; i++)
                {
                    SForce.Contact ctChildId = qrChildrenId.records[i] as SForce.Contact;

                    lstChildId.Add(ctChildId.Id);
                }
            }

            String strQueryForMedicareDetails = "select c4g_Qualifies_for_Medicare__c, c4g_Qualifies_for_Medicare_A_and_B__c from Contact " +
                                                " where cmm_Household__c = '" + strAccountId + "' and cmm_Household_Role__c = 'Head of Household'";

            SForce.QueryResult qrQualifyForMedicare = Sfdcbinding.query(strQueryForMedicareDetails);

            if (qrQualifyForMedicare.size > 0)
            {
                SForce.Contact ctQualifyForMedicare = qrQualifyForMedicare.records[0] as SForce.Contact;

                if (ctQualifyForMedicare.c4g_Qualifies_for_Medicare__c == true && ctQualifyForMedicare.c4g_Qualifies_for_Medicare__cSpecified == true)
                {
                    rbListMedicareYesNo.SelectedIndex = 0;
                }
                else if (ctQualifyForMedicare.c4g_Qualifies_for_Medicare__c == false && ctQualifyForMedicare.c4g_Qualifies_for_Medicare__cSpecified == true)
                {
                    rbListMedicareYesNo.SelectedIndex = 1;
                }

                if (ctQualifyForMedicare.c4g_Qualifies_for_Medicare_A_and_B__c == true && ctQualifyForMedicare.c4g_Qualifies_for_Medicare_A_and_B__cSpecified == true)
                {
                    rbListMedicareAandB.SelectedIndex = 0;
                }
                else if (ctQualifyForMedicare.c4g_Qualifies_for_Medicare_A_and_B__c == false && ctQualifyForMedicare.c4g_Qualifies_for_Medicare_A_and_B__cSpecified == true)
                {
                    rbListMedicareAandB.SelectedIndex = 1;
                }
            }

            if (!IsPostBack)
            {
                String strQueryForMemberPlan = "select c4g_Plan__r.Name from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                               "and cmm_Household_Role__c = 'Head of Household'";

                SForce.QueryResult qrMemberPlan = Sfdcbinding.query(strQueryForMemberPlan);

                if (qrMemberPlan.size > 0)
                {
                    SForce.Contact ctMemberPlan = qrMemberPlan.records[0] as SForce.Contact;

                    if (ctMemberPlan.c4g_Plan__r != null)
                    {
                        switch (ctMemberPlan.c4g_Plan__r.Name)
                        {
                        case "Gold Medi-I":
                            ddlParticipantProgram.SelectedIndex = 1;
                            break;

                        case "Gold Medi-II":
                            ddlParticipantProgram.SelectedIndex = 2;
                            break;

                        case "Gold Plus":
                            ddlParticipantProgram.SelectedIndex = 3;
                            break;

                        case "Gold":
                            ddlParticipantProgram.SelectedIndex = 4;
                            break;

                        case "Silver":
                            ddlParticipantProgram.SelectedIndex = 5;
                            break;

                        case "Bronze":
                            ddlParticipantProgram.SelectedIndex = 6;
                            break;
                        }
                    }
                }

                String strQueryForSpousePlan = "select c4g_Plan__r.Name from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                               "and cmm_Household_Role__c = 'Spouse'";

                SForce.QueryResult qrSpousePlan = Sfdcbinding.query(strQueryForSpousePlan);

                if (qrSpousePlan.size > 0)
                {
                    SForce.Contact ctSpousePlan = qrSpousePlan.records[0] as SForce.Contact;

                    if (ctSpousePlan.c4g_Plan__r != null)
                    {
                        switch (ctSpousePlan.c4g_Plan__r.Name)
                        {
                        case "Gold Medi-I":
                            ddlSpouseProgram.SelectedIndex = 1;
                            break;

                        case "Gold Medi-II":
                            ddlSpouseProgram.SelectedIndex = 2;
                            break;

                        case "Gold Plus":
                            ddlSpouseProgram.SelectedIndex = 3;
                            break;

                        case "Gold":
                            ddlSpouseProgram.SelectedIndex = 4;
                            break;

                        case "Silver":
                            ddlSpouseProgram.SelectedIndex = 5;
                            break;

                        case "Bronze":
                            ddlSpouseProgram.SelectedIndex = 6;
                            break;
                        }
                    }
                }

                String strQueryForChildren = "select c4g_Plan__r.Name from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                             "and cmm_Household_Role__c = 'Child'";

                SForce.QueryResult qrChildrenProgram = Sfdcbinding.query(strQueryForChildren);

                if (qrChildrenProgram.size > 0)
                {
                    SForce.Contact ctChildProgram = qrChildrenProgram.records[0] as SForce.Contact;

                    if (ctChildProgram.c4g_Plan__r != null)
                    {
                        switch (ctChildProgram.c4g_Plan__r.Name)
                        {
                        case "Gold Plus":
                            ddlChildrenProgram.SelectedIndex = 1;
                            break;

                        case "Gold":
                            ddlChildrenProgram.SelectedIndex = 2;
                            break;

                        case "Silver":
                            ddlChildrenProgram.SelectedIndex = 3;
                            break;

                        case "Bronze":
                            ddlChildrenProgram.SelectedIndex = 4;
                            break;
                        }
                    }
                }
            }

            String strQueryForChurchId = "select Id, c4g_Church__c from Contact where cmm_Household__c = '" + strAccountId + "' " +
                                         "and cmm_Household_Role__c = 'Head of Household'";

            SForce.QueryResult qrChurchId = Sfdcbinding.query(strQueryForChurchId);

            if (qrChurchId.size > 0)
            {
                SForce.Contact ctChurchId = qrChurchId.records[0] as SForce.Contact;

                String strQueryForChurchInfo = "select Name, Senior_Pastor_s_Name__c, ShippingAddress, Phone from Account where RecordTypeId = '01237000000R6cjAAC' and " +
                                               "Id = '" + ctChurchId.c4g_Church__c + "'";

                SForce.QueryResult qrAcctChurchInfo = Sfdcbinding.query(strQueryForChurchInfo);

                if (qrAcctChurchInfo.size > 0)
                {
                    SForce.Account acctChurchInfo = qrAcctChurchInfo.records[0] as SForce.Account;

                    txtChurchName.Text          = acctChurchInfo.Name;
                    txtSeniorPastor.Text        = acctChurchInfo.Senior_Pastor_s_Name__c;
                    txtChurchStreetAddress.Text = acctChurchInfo.ShippingAddress.street;
                    txtChurchZipCode.Text       = acctChurchInfo.ShippingAddress.postalCode;
                    ddlChurchState.Items.Add(new ListItem(acctChurchInfo.ShippingAddress.state));
                    ddlChurchState.SelectedIndex = 0;
                    ddlChurchCity.Items.Add(new ListItem(acctChurchInfo.ShippingAddress.city));
                    ddlChurchCity.SelectedIndex = 0;
                    txtChurchPhone.Text         = acctChurchInfo.Phone;
                }
            }

            //SForce.DescribeSObjectResult describeSObjectResult = Sfdcbinding.describeSObject("Contact");

            //// Get the fields
            //if (describeSObjectResult != null)
            //{
            //    SForce.Field[] fields = describeSObjectResult.fields;

            //    for (int i = 0; i < fields.Length; i++)
            //    {
            //        SForce.Field field = fields[i];

            //        if (field.name == "Referral_Source__c")
            //        {
            //            SForce.PicklistEntry[] pickListValues = field.picklistValues;
            //            if (pickListValues != null)
            //            {
            //                //ddlReferredBy.Items.Clear();
            //                foreach (SForce.PicklistEntry pickListEntry in pickListValues)
            //                {
            //                    ddlReferredBy.Items.Add(pickListEntry.value);
            //                }
            //            }
            //        }
            //    }
            //}


            //String strQueryForChurchInfo = "select Name, Senior_Pastor_s_Name__c, ShippingAddress, Phone from Account where RecordTypeId = '01237000000R6cjAAC' and " +
            //                   "Id = '" + strAccountId + "'";

            //String strQueryForChurchInfo = "select Name, Senior_Pastor_s_Name__c, ShippingAddress, Phone from Account where Id = '" + strAccountId + "'";

            if (!IsPostBack)
            {
                ////////////////////////////////////////////////////////////////////////
                // if no spouse is added, then clear the ddlSpouseProgram dropdownlist
                SForce.QueryResult qrSpouse = Sfdcbinding.query(strQueryForSpouse);
                if (qrSpouse.size == 0)
                {
                    ddlSpouseProgram.Items.Clear();
                }

                // if no child is added, then clear the ddlChildProgram dropdownlist
                SForce.QueryResult qrChild = Sfdcbinding.query(strQueryForChildren);
                if (qrChild.size == 0)
                {
                    ddlChildrenProgram.Items.Clear();
                }

                SForce.DescribeSObjectResult describeSObjectResult = Sfdcbinding.describeSObject("Membership__c");

                // Get the fields
                if (describeSObjectResult != null)
                {
                    SForce.Field[] fields = describeSObjectResult.fields;

                    for (int i = 0; i < fields.Length; i++)
                    {
                        SForce.Field field = fields[i];

                        if (field.name == "Referred_By__c")
                        {
                            SForce.PicklistEntry[] pickListValues = field.picklistValues;
                            if (pickListValues != null)
                            {
                                //ddlReferredBy.Items.Clear();
                                foreach (SForce.PicklistEntry pickListEntry in pickListValues)
                                {
                                    ddlReferredBy.Items.Add(pickListEntry.value);
                                }
                            }
                        }
                    }
                }
            }

            //strAccountID = (String)Session["AccountId"];
            //strSpouseId = (String)Session["ContactId"];
        }