DayPilot Forums

DayPilot is the best open-source Outlook-like calendar control for ASP.NET.
DayPilot Pro Demo (Calendar control)
» DayPilot Pro live demo (Calendar control)
DayPilot Pro Demo (Scheduler control)
» DayPilot Pro live demo (Scheduler control)
Home » General » Ajax callback doing calendar #Update() doesn't update calendar

Ajax callback doing calendar #Update() doesn't update calendar

Hi,

I am using an Ajax control that has an async callback. This callback looks like this:

protected void dtpDatumVanaf_TextChanged(object sender, EventArgs e)
{
Gaia.WebWidgets.DateTimePicker picker = (Gaia.WebWidgets.DateTimePicker)sender;
calSchema.StartDate = DayPilot.Utils.Week.FirstDayOfWeek(picker.Value.Value);
calSchema.Update();
}

Unfortunately this does not update the calendar control. Any idea why this doesn't work? From what I've read Update() is specifically designed to update the calendar from async callbacks. I am using a Daypilot 4.2 Pro trial version.
Dirk Louwers - 12/14/2007 11:01:38 AM
The DayPilot callback works only if it was invoked by DayPilot's methods. It can be invoked automatically (e.g. if you set EventDeleteHandling="CallBack") or manually from the JavaScript code (e.g. dpc.eventDeleteCallBack(e) for the delete event).

You have two choices:
  • Check if Gaia.WebWidgets.DateTimePicker is able to run custom JavaScript after the callback is finished. You could call the refresh() method from there. This would mean two callbacks in total (first for the DateTimePicker and a second for the DayPilot).
  • You can put both controls inside an UpdatePanel and switch to PostBack handling. Then it will be a single callback ("partial PostBack") but it will be a bit slower.
In either case, don't forget to call calSchema.DataBind() to actually refresh the data.
Dan Letecky - 12/14/2007 11:49:35 AM
Thanks for your reply.

Just as a FYI for other users of Gaia, I have done the following:
protected void dtpDatumVanaf_TextChanged(object sender, EventArgs e)
{
DateTime date = DayPilot.Utils.Week.FirstDayOfWeek(dtpDatumVanaf.Value.Value, DayOfWeek.Tuesday);
Gaia.WebWidgets.Manager.Instance.AddScriptForClientSideEval(calSchema.ClientObjectName + ".refreshCallBack(new Date(" + date.Year + ", " + (date.Month - 1) + ", " + date.Day + "),null);");
}

This works, but the only thing that really puzzles me is why I have had to set the weekStarts parameter of the FirstDayOfWeek method to DayOfWeek.Tuesday to make it display Monday as the fist day of the week. Any clues?

Kind regards,

Dirk Louwers
Dirk Louwers - 12/14/2007 4:04:42 PM
Thanks for posting the solution.

The Week.FirstDayOfWeek method is as simple as this:

        public static DateTime FirstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}

return d;
}
The problem seems to be somewhere else.

All times are passed as relative values to the client-side (that means the server time zone is ignored and "2007-12-14 15:00:00 +0900" is passed as "2007-12-14 15:00:00 +0000") and they during the lifetime of the client objects they are handled as GMT values.

The reason for this is that IE and FF handle summer time differently (IE is converting the time to a the summer time zone automatically during setTime() operations).

For passing the DateTime values DayPilot is using the following method:
public static string FormatDateTime(DateTime dt)
{
return dt.ToString("MMMM d, yyyy HH:mm:ss +0000", CultureInfo.CreateSpecificCulture("en-US"));
}
You are passing it as new Date(" + date.Year + ", " + (date.Month - 1) + ", " + date.Day + ") which most likely adds the current time zone to it. You can try using this instead:
Gaia.WebWidgets.Manager.Instance.AddScriptForClientSideEval(calSchema.ClientObjectName +
".refreshCallBack(new Date(" + DayPilot.Utils.JsDate.FormatDateTime(d) + "),null);");

Dan Letecky - 12/14/2007 7:01:54 PM
Yes, that works. Please note though that the generated date has to be passed to the constructor of date as a string so the code would become:
Gaia.WebWidgets.Manager.Instance.AddScriptForClientSideEval(calSchema.ClientObjectName +
 ".refreshCallBack(new Date(\"" + DayPilot.Utils.JsDate.FormatDateTime(d) + "\"),null);");
Dirk Louwers - 12/17/2007 2:17:45 PM
Thanks, Dirk!
Dan Letecky - 12/17/2007 3:37:00 PM
Post reply