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

dpc1.commandCallBack("refresh") (javascript) will not refesh calendar (asp.net)

Asked by David East
8 years ago.

Hi, I'm trying to refresh the calendar from a Javescript function. The first time the page is loaded, the function fires as expected and the calendar is updated; after that initial working action, it will never update again. I've tried postback, callback, JavaScript, voodoo dolls, four leaf clovers, a threat of physical force, yet it won't work. Here's the entire javascript:

function editStaff() {
var modal = new DayPilot.Modal();
modal.top = 60;
modal.width = 300;
modal.height = 400;
modal.opacity = 0;
modal.border = "10px solid #d0d0d0";
modal.closed = function () {
if (this.result != "cancel") {
dpc1.commandCallBack("refresh");
}
};
var curText = document.getElementById("<%= hfStaffName.UniqueID %>").value;
if (curText.length > 0) {
var url = "staff/editstaff.aspx?staff=" + curText;
modal.showUrl(url);
}
}

<daypilot:daypilotcalendar id="DayPilotCalendar1" runat="server" ShowAllDayEventStartEnd="true"
AllDayEventBackColor="Gray"
AllDayEnd="DateTime"
CellBorderColor="#000000"
datastartfield="eventstart"
dataendfield="eventend"
datatextfield="ItemDesc"
datavaluefield="id"
datatagfields="color,name"
DataAllDayField="allday"
BusinessBeginsHour="8"
BusinessEndsHour="22"
ViewType="Resources"
DataColumnField="resource"
OnEventMove="DayPilotCalendar1_EventMove"
OnEventClick="DayPilotCalendar1_EventClick"
OnEventEdit="DayPilotCalendar1_EventEdit"
OnBeforeEventRender="DayPilotCalendar1_BeforeEventRender"
OnEventDelete="DayPilotCalendar1_EventDelete"
OnEventSelect="DayPilotCalendar1_EventSelect"
OnEventResize="DayPilotCalendar1_EventResize"
OnTimeRangeSelected="DayPilotCalendar1_TimeRangeSelected"
OnTimeRangeDoubleClick="DayPilotCalendar1_TimeRangeDoubleClick"
OnTimeRangeMenuClick="DayPilotCalendar1_TimeRangeMenuClick"
OnCommand="DayPilotCalendar1_Command"
OnBeforeCellRender="DayPilotCalendar1_BeforeCellRender"
OnBeforeTimeHeaderRender="DayPilotCalendar1_BeforeTimeHeaderRender"
OnEventMenuClick="DayPilotCalendar1_EventMenuClick"
EventMoveHandling="Callback"
TimeRangeSelectedHandling="Postback"
EventDeleteJavaScript="if (confirm('Do you really want to delete ' + e.text() + ' ?')) dpc1.eventDeleteCallBack(e);"
EventResizeHandling="CallBack"
EventClickHandling="Postback"
EventSelectHandling="Postback"
ClientObjectName="dpc1"
EventEditHandling="Callback"
EventDeleteHandling="Postback"
EventSelectColor="Blue"
HeightSpec="BusinessHoursNoScroll"
ContextMenuID="DayPilotMenu1"
Showalldayevents="false"
Useeventboxes="Always"
ShowToolTip="true"
EventDoubleClickHandling="PostBack"
EventDoubleClickJavaScript="alert(e.value());"
TimeRangeDoubleClickHandling="Postback"
TimeFormat="Clock12Hours"
ContextMenuSelectionID="DayPilotMenuSelection"
CssClassPrefix="calendar_silver_"
HourNameBackColor=""
BorderColor="#A0A0A0"
HourBorderColor="Black"
HourHalfBorderColor="Black"
EventBorderColor="#505050"
AllDayEventBorderColor="#ff0000"
EventArrangement="SideBySide"
CellDuration="15"
HeaderLevels="2"
HeaderDateFormat="dddd MMMM d,yyyy"
OnHeaderClick = "DayPilotCalendar1_HeaderClick1"
HeaderClickHandling="Postback"
></daypilot:daypilotcalendar>

Code behind:

Protected Sub DayPilotCalendar1_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim sMsg As String = Nothing
Select Case e.Command
Case "previous"
DayPilotCalendar1.StartDate = DayPilotCalendar1.StartDate.AddDays(-1)
LoadEvents()
defineColumns()
DayPilotCalendar1.DataBind()
DayPilotCalendar1.Update(CallBackUpdateType.Full)
Exit Select
Case "next"
DayPilotCalendar1.StartDate = DayPilotCalendar1.StartDate.AddDays(1)
'lblCalHead.Text = DayPilotCalendar1.StartDate.ToString("MMMM yyyy")
LoadEvents()
defineColumns()
DayPilotCalendar1.DataBind()
DayPilotCalendar1.Update(CallBackUpdateType.Full)
Exit Sub
Case "today"
DayPilotCalendar1.StartDate = DateTime.Today
LoadEvents()
defineColumns()
DayPilotCalendar1.DataBind()
DayPilotCalendar1.Update(CallBackUpdateType.Full)
Exit Sub
Case "navigate"
Dim start As DateTime = CType(e.Data("start"), DateTime)
Dim [end] As DateTime = CType(e.Data("end"), DateTime)
DayPilotCalendar1.StartDate = start.AddDays(DayPilotCalendar1.Days - 1)
LoadEvents()
defineColumns()
DayPilotCalendar1.DataBind()
DayPilotCalendar1.Update(CallBackUpdateType.Full)
Exit Sub
Case "refresh"
LoadEvents()
defineColumns()
DayPilotCalendar1.DataBind()
DayPilotCalendar1.Update(CallBackUpdateType.Full)
Exit Sub
End Select
End Sub

I'm totally lost here and my client is really getting impatient. Any help you could give me would be most appreciated.

Comment posted by Rhys
8 years ago.

You need to refresh the data source before you do your data bind, not sure if that is what the LoadEvents() function is doing but you should be setting the data source and then performing a data bind before doing the update

Comment posted by David East
8 years ago.

Sorry, I forgot to include that function. Here are the LoadEvents and DefineColumns functions:

Private Sub LoadEvents()
Dim start As DateTime = DayPilotCalendar1.StartDate
Dim ende As DateTime = DayPilotCalendar1.StartDate.AddDays(DayPilotCalendar1.Days)

DayPilotCalendar1.DataSource = DataGenerator.GetDataByStartRange(start, 3)
End Sub

Private Sub defineColumns()
DayPilotCalendar1.Columns.Clear()

Dim first As DateTime = DayPilotCalendar1.StartDate

Dim aRes As ArrayList = DataGenerator.GetResourceString

For i As Integer = 0 To aRes.Count - 1

Dim c As New Column(aRes(i), aRes(i))
DayPilotCalendar1.Columns.Add(c)

For j As Integer = 0 To 0
Dim day As DateTime = first.AddDays(j)

Dim subC As New Column(day.ToShortDateString(), aRes(i))
subC.[Date] = day
c.Children.Add(subC)

Next
Next
End Sub

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.