protected void btnSave_Click(object sender, EventArgs e) { try { var holidayEvent = (ControlMode == SPControlMode.New) ? new HolidayEvent() { Id = Guid.NewGuid() } : Item; if (holidayEvent == null) { throw new Exception("Holiday event is empty"); } if (holidayEvent.Holiday == null) { holidayEvent.Holiday = new Holiday { Id = Guid.NewGuid() }; } // set Holiday Name holidayEvent.Holiday.Name = (holidayForm.FindControl("txtName") as TextBox).Text; // set Holiday Date holidayEvent.HolidayDate = (holidayForm.FindControl("dtHolidayDate") as DateTimeControl).SelectedDate; // set Holiday type DropDownList ddlType = holidayForm.FindControl("ddlType") as DropDownList; holidayEvent.Holiday.TypeId = ddlType.SelectedValue.ToInt(); // set Observeds ListBox ddlObserved = holidayForm.FindControl("ddlObserved") as ListBox; holidayEvent.HolidayObserveds.Clear(); foreach (ListItem li in ddlObserved.Items.Cast <ListItem>().Where(itm => itm.Selected)) { holidayEvent.HolidayObserveds.Add(new HolidayObserved { Id = Guid.NewGuid(), HolidayEventId = holidayEvent.Id, StateId = 6 }); } _dataService.SaveHoliday(holidayEvent); Utils.GoBackOnSuccess(this.Page, this.Context); } catch (Exception ex) { ErrorHolder.Controls.Add(new Label { Text = ex.ToReadbleSrting("Saving Error"), ForeColor = System.Drawing.Color.Red }); } }