Telerik RadScheduler cancel appointment move after Server-Side validation error

277 Views Asked by At

I am using Telerik RadScheduler with Web Service binding.

When I drag an appointment to another timeslot, I do some client-side validation in OnClientAppointmentMoveEnd, and if that succeeds I set args.set_cancel(true);

It then hits my web service method UpdateAppointment.

My server side code within this web service call then does some additional validation based on a database query.

My question is - if this server side validation fails, how can I get the client-side appointment to move back to where it originated? I can catch a status or message in OnClientRequestFailed but is there a way to cancel the move event after the web service call, or move the appointment back?

1

There are 1 best solutions below

0
On

I just found my own answer - After the UpdateAppointment web method is called, the scheduler will then call GetAppointments again, so the correct data should be reloaded on the client.

For others who might find this useful:

  1. Do not throw an Exception in UpdateAppointment for a validation error. I set the error message in Session (couldn't find a way to pass it back from the Provider to the Web Method)
  2. I created a class MySchedulerResult inheriting from SchedulerOperationResult<AppointmentData>, with an ErrorMessage property.
  3. My UpdateAppointment Web Method returns this MySchedulerResult and assigns the Appointments returned from Provider.UpdateAppointment to it. It checks the Session to see if a validation error occurred, and sets the ErrorMessage property to this value if found.
  4. My OnClientRequestSuccess method on the client side unpacks this result and pops up the error message if found. Meanwhile the appointment data is getting reloaded and should have the changed appointment back in its original timeslot.

I found more info around the scheduler result class here: http://docs.telerik.com/devtools/aspnet-ajax/controls/scheduler/web-service-binding/returning-extra-data-from-the-web-service