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

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

Asked by Dirk Louwers
16 years ago.
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.
Comment posted by Dan Letecky
16 years ago.
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.
Comment posted by Dirk Louwers
16 years ago.
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
Comment posted by Dan Letecky
16 years ago.
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);");

Comment posted by Dirk Louwers
16 years ago.
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);");
Comment posted by Dan Letecky
16 years ago.
Thanks, Dirk!
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.