Skip to main content

ASPxSchedulerDataWebControlBase.AppointmentDeleting Event

Occurs before an appointment is deleted and allows you to cancel the action.

Namespace: DevExpress.Web.ASPxScheduler

Assembly: DevExpress.Web.ASPxScheduler.v24.1.dll

NuGet Package: DevExpress.Web.Scheduler

Declaration

public event PersistentObjectCancelEventHandler AppointmentDeleting

Event Data

The AppointmentDeleting event's data class is PersistentObjectCancelEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets whether to cancel the operation.
Object Gets the persistent object (appointment, resource or appointment dependency) for which the event occurs. Inherited from PersistentObjectEventArgs.

Remarks

The AppointmentDeleting event is raised before an appointment is deleted and allows you to cancel the deletion of an appointment. To accomplish this, set the PersistentObjectCancelEventArgs.Cancel property to true.

Example

The following example illustrates how to use the ASPxSchedulerDataWebControlBase.AppointmentDeleting event. In this event, the scheduler deletes all appointments that belong to a single series. When deleting an appointment, an end user confirms whether or not to remove an entire series or just the occurrence (this information is saved to the hidden field). The “DeleteMode” hidden field stores the end user’s choice. Appointments which belong to a single series are fetched using the CustomRecurringID field value. The end-user is not allowed to delete an appointment with “Completed” status (specified using the ASPxAppointmentCustomFieldMapping object).

protected void ASPxScheduler1_AppointmentDeleting(object sender, PersistentObjectCancelEventArgs e) {
    if(isLocked) return;

    ASPxSchedulerStorage storage = sender as ASPxSchedulerStorage;
    Appointment deletedAppointment = e.Object as Appointment;
    if(hfDeleteMode.Contains("DeleteMode") && Convert.ToBoolean(hfDeleteMode["DeleteMode"]) && deletedAppointment.CustomFields["CustomRecurringID"] != null) {
        isLocked = true;

        string currentRecID = deletedAppointment.CustomFields["CustomRecurringID"].ToString();
        storage.BeginUpdate();
        List<Appointment> occurrences = storage.Appointments.Items.Where(appt => appt.CustomFields["CustomRecurringID"] != null && appt.CustomFields["CustomRecurringID"].ToString() == currentRecID).ToList();

        foreach(Appointment item in occurrences) {
            if(Convert.ToInt32(item.Id) != Convert.ToInt32(deletedAppointment.Id)) {
                storage.Appointments.Remove(item);
            }
        }
        storage.EndUpdate();

        isLocked = false;
        hfDeleteMode["DeleteMode"] = false;
    }
}
...
protected void ASPxScheduler1_InitClientAppointment(object sender, InitClientAppointmentEventArgs args) {
    args.Properties.Add("cpCompleted", args.Appointment.CustomFields["LessonCompleted"]);
    args.Properties.Add("cpCustomRecurringFlag", args.Appointment.CustomFields["CustomRecurringFlag"]);
    args.Properties.Add("cpCustomRecurringID", args.Appointment.CustomFields["CustomRecurringID"]);
}
See Also