protected void updateButton_Click(object sender, EventArgs e) { if (Validation() && Page.IsValid) { int?availabilityId = null; using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { bool availabilityPresent = false; if (ViewState["AvailabilityPresent"] != null) { availabilityPresent = Convert.ToBoolean(ViewState["AvailabilityPresent"]); } if (availabilityPresent) { //update availability dataContext.UpdateAvailability(StoredData.User.UserId, sundayFromRadTimePicker.SelectedDate, sundayToRadTimePicker.SelectedDate, sundayUnavailableCheckBox.Checked, mondayFromRadTimePicker.SelectedDate, mondayToRadTimePicker.SelectedDate, mondayUnavailableCheckBox.Checked, tuesdayFromRadTimePicker.SelectedDate, tuesdayToRadTimePicker.SelectedDate, tuesdayUnavailableCheckBox.Checked, wednesdayFromRadTimePicker.SelectedDate, wednesdayToRadTimePicker.SelectedDate, wednesdayUnavailableCheckBox.Checked, thursdayFromRadTimePicker.SelectedDate, thursdayToRadTimePicker.SelectedDate, thursdayUnavailableCheckBox.Checked, fridayFromRadTimePicker.SelectedDate, fridayToRadTimePicker.SelectedDate, fridayUnavailableCheckBox.Checked, saturdayFromRadTimePicker.SelectedDate, saturdayToRadTimePicker.SelectedDate, saturdayUnavailableCheckBox.Checked); } else { dataContext.InsertAvailability(StoredData.User.UserId, sundayFromRadTimePicker.SelectedDate, sundayToRadTimePicker.SelectedDate, sundayUnavailableCheckBox.Checked, mondayFromRadTimePicker.SelectedDate, mondayToRadTimePicker.SelectedDate, mondayUnavailableCheckBox.Checked, tuesdayFromRadTimePicker.SelectedDate, tuesdayToRadTimePicker.SelectedDate, tuesdayUnavailableCheckBox.Checked, wednesdayFromRadTimePicker.SelectedDate, wednesdayToRadTimePicker.SelectedDate, wednesdayUnavailableCheckBox.Checked, thursdayFromRadTimePicker.SelectedDate, thursdayToRadTimePicker.SelectedDate, thursdayUnavailableCheckBox.Checked, fridayFromRadTimePicker.SelectedDate, fridayToRadTimePicker.SelectedDate, fridayUnavailableCheckBox.Checked, saturdayFromRadTimePicker.SelectedDate, saturdayToRadTimePicker.SelectedDate, saturdayUnavailableCheckBox.Checked, ref availabilityId); } string errorMessage = "radalert('Availability updated succesfully!!',250,150,'Success!!')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + errorMessage + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})();", true); } } }