protected void _btnSave_Click(object sender, EventArgs e) { string errorMessage = CheckMandatoryFields(); if (string.IsNullOrEmpty(errorMessage)) { DiaryServiceClient diaryService = null; try { IRIS.Law.WebServiceInterfaces.Diary.Appointment appointmentDetails = GetControlData(); diaryService = new DiaryServiceClient(); AppointmentReturnValue returnValue = diaryService.SaveAppointment(_logonSettings.LogonId, appointmentDetails); if (returnValue.Success) { _hdnAppointmentId.Value = Convert.ToString(returnValue.Appointment.Id); _lblError.CssClass = "successMessage"; _lblError.Text = "Appointment Saved Successfully."; } else { _lblError.CssClass = "errorMessage"; if (returnValue.Message == "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.") { _lblError.Text = "Date is invalid"; } else { _lblError.Text = returnValue.Message; } } } catch (System.ServiceModel.EndpointNotFoundException) { _lblError.Text = DataConstants.WSEndPointErrorMessage; _lblError.CssClass = "errorMessage"; } catch (Exception ex) { _lblError.CssClass = "errorMessage"; _lblError.Text = ex.Message; } finally { if (diaryService != null) { if (diaryService.State != System.ServiceModel.CommunicationState.Faulted) { diaryService.Close(); } } } } else { _lblError.CssClass = "errorMessage"; _lblError.Text = errorMessage; } }