The commandCallBack() method can be used to send custom command with custom data to the server side.
Typical Use
- Reload the event data
- Switch the visible time range
- Refresh the control after changing the resources
- Filtering the visible events
How It Works
When you invoke the commandCallBack() function on the client-side DayPilot Calendar object, it will fire the Command event handler on the server-side using an AJAX call.
In the Command event handler you should call Update() after doing your work and reloading the events using DataBind().
See also: Update() method
Parameters
- command (string) - custom command type string
- data (any JavaScript object) - custom data that will be sent to the server-side Command handler
The data parameter will be translated into JsonData class - see also Sending custom data with CallBack.
Reference
ASP.NET WebForms
Example (switching to a specified year)
.aspx
<a href="javascript:dpc.commandCallBack('year', 2013);">Next</a>
.aspx.cs:
protected void DayPilotCalendar1_Command(object sender, CommandEventArgs e) { switch (e.Command) { case "year": DayPilotCalendar1.StartDate = new DateTime((int)e.Data, 1, 1); break; // ... } // ... DayPilotCalendar1.DataBind(); DayPilotCalendar1.Update(); }
ASP.NET MVC
Example (requesting a refresh)
MVC View
<a href="javascript:dpc.commandCallBack('refresh');">Refresh</a> @(Html.DayPilotCalendar("dpc", new DayPilotCalendarConfig { BackendUrl = Url.Content("~/Calendar/Backend"), ViewType = DayPilot.Web.Mvc.Enums.Calendar.ViewType.Week, // ... }))
MVC Controller
public class Dpc : DayPilotCalendar { // ... protected override void OnCommand(CommandArgs e) { switch (e.Command) { case "refresh": Events = new EventManager(Controller).Data.AsEnumerable(); DataStartField = "start"; DataEndField = "end"; DataTextField = "text"; DataIdField = "id"; Update(); break; } } }