search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Javascript eventMoveCallBack

Asked by Scott Lee
12 years ago.

I am trying to do a javascript callback to handle the move of an event.

ASPX:

<DayPilot:DayPilotCalendar ID="schedule" runat="server" HeightSpec="Full" CellsPerHour="4" ShowHeader="true" ViewType="Resources" DataStartField="start" DataEndField="end" DataTextField="description" DataValueField="service_id" DataColumnField="column" HeaderHeight="40" Width="100%" EventMoveHandling="JavaScript" EventMoveJavaScript="Schedule_onMoveAppointment(e, newStart, newEnd, oldColumn, newColumn)" OnEventMove="schedule_EventMove">
</DayPilot:DayPilotCalendar>

JAVASCRIPT:

function Schedule_onMoveAppointment(eventArgs, newStart, newEnd, oldColumn, newColumn)
{
alert("newStart:" + newStart + "\n\rnewEnd:" + newStart + "\n\roldColumn:" + oldColumn + "\n\rnewColumn:" + newColumn);
alert(eventArgs.value());
_ctl0_MainPageContent_schedule.eventMoveCallBack(eventArgs, newStart, newEnd, oldColumn, newColumn);
}

SERVER SIDE:

protected void schedule_EventMove(object sender, DayPilot.Web.Ui.Events.EventMoveEventArgs e)
{
// Update your database
// ...
DataRow[] dr = dsObjResults.Tables["getsched"].Select("service_id = " + e.Value);
if (dr.Length > 0)
{
dr[0]["startafter"] = System.Convert.ToInt16(e.NewStart.ToString("HHmm"));
dr[0]["schedtime"] = System.Convert.ToInt16(e.NewStart.ToString("HHmm"));
dr[0]["endbefore"] = System.Convert.ToInt16(e.NewEnd.ToString("HHmm"));
dr[0]["startdate"] = Convert.ToDateTime(e.NewStart.ToShortDateString());
}
DataTable dt = CreateDayPilotTable(dsObjResults.Tables["getsched"]);
schedule.DataSource = dt;
schedule.DataBind();
schedule.Update();
hdnPageXml.Value = DataUtils.GetXmlFromDataSet(dsObjResults, true);
}

All of the code gets executed, and I have debugged to see that the datatable contains the correct data. The call finishes and the calendar does not reflect the event move. Any idea what I am doing wrong?

Comment posted by Dan Letecky
12 years ago.
From you snippet it's not clear if it's complete:

// Update your database
// ...

If you didn't skip any code it seems schedule_EventMove doesn't actually change the bound columns ("start" and "end" that are specified in DataStartField and DataEndField).

Just a note:

hdnPageXml.Value = DataUtils.GetXmlFromDataSet(dsObjResults, true);

The following code won't have any effect. CallBack updates just the events on the client side. You can't touch any other control on the page. If you need to update something else, call schedule.Update(yourData) and handle yourData in AfterRenderJavaScript (see Sending custom data back to the client after a CallBack (DayPilotCalendar & DayPilotScheduler) section in DayPilot Pro 4.1 release notes).
Comment posted by Scott Lee
12 years ago.

The call to CreateDayPilotTable(datatable) creates the datatable bound to the calendar based on the argument dsObjResults.Tables["getsched"]. The code I posted updates that table first then calls CreateDayPilotTable(datatable) which returns the table that is bound to the calendar.

This code works if I do it via Postback, just not Callback or Javascript (Callback).

When debugging (Callback or Javascript) the handler code is executed, data is the same as when I use Postback but the client does not update and the client handler for AfterRenderJavaScript never gets called.

NOTE: I do realize that I cannot update other components via the Callback (I plan to use AfterRenderJavaScript to accomplish that). Sorry for leaving that in the snippet.

Comment posted by Scott Lee
12 years ago.
Turns out there was other data in the response buffer when I made the call to Update(). My work around is to call Response.Clear() just before calling Update(). You may want to overload Update with a second argument (enum) declaring whether the update is for Postback or Callback and if it is Callback clear the response buffer first.
Answer posted by Dan Letecky
12 years ago.
If you write anything using Response.Write() during a CallBack it will corrupt the response. However, it should throw some kind of a JavaScript error on the client side, did you experience that?

I will check if there is any chance to detect this situation in DayPilot and throw a warning.

It's also helpful to use Firefox + Firebug to debug the CallBack issues (you can see all the callbacks, including the request and response).

A small clarification on Update(): It just sets a flag that is evaluated after the event handler is done so the order of calling Response.Clear()/DayPilotCalendar.Update() doesn't matter here.
Comment posted by Scott Lee
12 years ago.
It did not throw any exception on the client. Just didn't repaint. In that section of code you look for the separater "|" and then test to see if the data up to that point is not NaN. If it is it just leaves the function.
Comment posted by Dan Letecky
12 years ago.
Sorry for the delay.

"|" separator is used by .NET Framework (the core CallBack handling code). It would be helpful if you tried to catch the full CallBack response (using Firefox + Firebug or Fiddler). It seems there is something wrong with the response.
This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.