/// <summary>
        /// Displays the address details for the selected address type.
        /// </summary>
        private void DisplayContactAddressDetails()
        {
            try
            {
                AddressSearchReturnValue addressSearchReturnValue = new AddressSearchReturnValue();
                CollectionRequest collectionRequest = new CollectionRequest();
                AddressSearchCriteria searchCriteria = new AddressSearchCriteria();
                searchCriteria.MemberId = _memberId;
                searchCriteria.OrganisationId = _organisationId;

                ContactServiceClient serviceClient = new ContactServiceClient();
                addressSearchReturnValue = serviceClient.GetContactAddresses(_logonSettings.LogonId, collectionRequest, searchCriteria);

                List<Address> contactAddresses = null;
                Address currentAddress = null;
                if (!IsPostBack)
                {
                    GetContactAddressTypes();
                    //Store the addresses in a list so that we can add items if necessary
                    contactAddresses = new List<Address>();
                    foreach (Address address in addressSearchReturnValue.Addresses.Rows)
                    {
                        contactAddresses.Add(address);
                    }
                    Session[SessionName.ClientAddresses] = contactAddresses;
                }
                else
                {
                    contactAddresses = (List<Address>)Session[SessionName.ClientAddresses];
                }

                //Get the current selected address type and display the address
                foreach (Address address in contactAddresses)
                {
                    if (address.TypeId == 1)
                    {
                        Session[SessionName.ContactDetails] = address.AdditionalAddressElements;
                    }

                    if (address.TypeId == Convert.ToInt32(_ddlAddressType.SelectedValue))
                    {
                        currentAddress = address;
                        break;
                    }
                }
                //If an address exists then display it..
                if (currentAddress != null)
                {
                    List<string> updatedAddresses = (List<string>)ViewState[UpdatedAddresses];
                    _ucAddress.Address = currentAddress;
                    _ucAddress.IsDataChanged = updatedAddresses.Contains(currentAddress.TypeId.ToString());
                    _ucAddress.DataBind();
                }
                else
                {
                    //No address exists for the current type, so create a new one
                    currentAddress = new Address();
                    currentAddress.LastVerified = DataConstants.BlankDate;
                    currentAddress.TypeId = Convert.ToInt32(_ddlAddressType.SelectedValue);
                    contactAddresses.Add(currentAddress);
                    _ucAddress.Address = currentAddress;
                    _ucAddress.IsDataChanged = false;
                    _ucAddress.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Saves the addresses.
        /// </summary>
        private void SaveAddresses()
        {
            ContactServiceClient contactService = null;
            ClientServiceClient clientService = null;
            try
            {
                CheckForModifiedAddress();
                List<string> updatedAddresses = (List<string>)ViewState[UpdatedAddresses];
                //Check if any of the addresses have been modified
                if (updatedAddresses.Count > 0)
                {
                    contactService = new ContactServiceClient();
                    List<Address> clientAddresses = (List<Address>)Session[SessionName.ClientAddresses];
                    foreach (string addressType in updatedAddresses)
                    {
                        foreach (Address address in clientAddresses)
                        {
                            if (address.TypeId.ToString() == addressType)
                            {

                                if (_logonSettings.UserType == (int)DataConstants.UserType.ThirdParty && Request.QueryString["mydetails"] == "true")
                                {
                                    address.MemberId = _logonSettings.MemberId;
                                    address.OrganisationId = _logonSettings.OrganisationId;
                                }
                                else
                                {
                                    address.MemberId = (Guid)Session[SessionName.MemberId];
                                    address.OrganisationId = (Guid)Session[SessionName.OrganisationId];
                                }

                                AddressReturnValue returnValue = contactService.SaveAddress(_logonSettings.LogonId, address);
                                if (!returnValue.Success)
                                {
                                    _lblMessage.CssClass = "errorMessage";
                                    _lblMessage.Text = returnValue.Message;
                                }
                                break;
                            }
                        }
                    }
                    updatedAddresses.Clear();
                    //Reload the addresses
                    clientService = new ClientServiceClient();
                    AddressSearchCriteria searchCriteria = new AddressSearchCriteria();
                    searchCriteria.MemberId = _memberId;
                    searchCriteria.OrganisationId = _organisationId;
                    CollectionRequest collectionRequest = new CollectionRequest();
                    collectionRequest.ForceRefresh = true;

                    if (Request.QueryString["mydetails"] == "true" && _logonSettings.UserType == (int)DataConstants.UserType.ThirdParty)
                    {
                        AddressSearchReturnValue addressSearchReturnValue = new AddressSearchReturnValue();
                        ContactServiceClient serviceClient = new ContactServiceClient();
                        addressSearchReturnValue = serviceClient.GetContactAddresses(_logonSettings.LogonId, collectionRequest, searchCriteria);
                        clientAddresses.Clear();
                        //Store the addresses in a list so that we can add items if necessary
                        foreach (Address address in addressSearchReturnValue.Addresses.Rows)
                        {
                            clientAddresses.Add(address);
                        }

                    }
                    else
                    {
                        AddressSearchReturnValue addresses = clientService.GetClientAddresses(_logonSettings.LogonId,
                                                                                            collectionRequest,
                                                                                            searchCriteria);
                        clientAddresses.Clear();
                        //Store the addresses in a list so that we can add items if necessary
                        foreach (Address address in addresses.Addresses.Rows)
                        {
                            clientAddresses.Add(address);
                        }
                    }

                    if (Request.QueryString["mydetails"] == "true" && _logonSettings.UserType == (int)DataConstants.UserType.ThirdParty)
                    {
                        DisplayContactAddressDetails();
                    }
                    else
                    {
                        DisplayAddressDetails();
                    }
                }
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                _lblMessage.Text = DataConstants.WSEndPointErrorMessage;
                _lblMessage.CssClass = "errorMessage";
            }
            catch (Exception ex)
            {
                _lblMessage.CssClass = "errorMessage";
                _lblMessage.Text = ex.Message;
            }
            finally
            {
                if (contactService != null)
                {
                    if (contactService.State != System.ServiceModel.CommunicationState.Faulted)
                        contactService.Close();
                }

                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                        clientService.Close();
                }
            }
        }