event-calendar-asp-net-mvc-autorefresh.png

The Calendar supports automatic event reloading (in specified intervals).

AutoRefresh is disabled by default. You can enable it using autoRefreshEnabled property.

Configuration properties:

  • autoRefreshEnabled (bool)
  • autoRefreshInterval (int) - number of seconds between automatic reloads
  • autoRefreshMaxCount(int) - maximum number of automatic reloads
  • autoRefreshCommand(string) - a command value that will be passed to Command event when requesting a reload

Client Side

JavaScript

If enabled using autoRefreshEnabled property, it will fire onAutoRefresh event in the specified intervals.

dp.autoRefreshInterval = 10; 
dp.autoRefreshMaxCount = 10;
dp.autoRefreshEnabled = true;

dp.onAutoRefresh = function(args) { 
  console.log("refreshing, iteration #" + args.i); 
};

ASP.NET WebForms

If enabled, AutoRefresh will fire the Command event on the server side with the value of AutoRefreshCommand as the command name.

.aspx

<DayPilot:DayPilotCalendar 
  ID="DayPilotCalendar1" 
  runat="server" 
  ...
  OnCommand="DayPilotCalendar1_Command" 
  AutoRefreshEnabled="true"
  AutoRefreshInterval="10"
  AutoRefreshMaxCount="12"
  />

.aspx.cs

protected void DayPilotCalendar1_Command(object sender, DayPilot.Web.Ui.Events.CommandEventArgs e)
{
  switch (e.Command)
  {
      case "refresh":
          setDataSourceAndBind();
          DayPilotCalendar1.DataBind();
          DayPilotCalendar1.UpdateWithMessage("Events refreshed automatically");
          break;
  }
}

Demo

ASP.NET MVC

View

@Html.DayPilotCalendar("dpc", new DayPilotCalendarConfig()
{
  BackendUrl = ResolveUrl("~/Calendar/Backend"),
  ...
  AutoRefreshEnabled = true,
  AutoRefreshInterval = 10,
  AutoRefreshMaxCount = 5
})

Controller

protected override void OnCommand(CommandArgs e)
{
  switch (e.Command)
  {
      case "refresh":
          UpdateWithMessage("Refreshed");
          break;
  }
}

protected override void OnFinish()
{
  // only load the data if an update was requested by an Update() call
  if (UpdateType == CallBackUpdateType.None)
  {
      return;
  }

  DateTime start = StartDate;
  DateTime end = StartDate.AddDays(Days + 1);

  Events = new EventManager(Controller).FilteredData(start, end).AsEnumerable();  // your method

  DataStartField = "start";
  DataEndField = "end";
  DataTextField = "text";
  DataIdField = "id";
}

Demo

The demo page refreshes the events every 10 seconds for 2 minutes (maximum 12 times):