Tutorial: Scheduler Printing (ASP.NET, C#, VB.NET)

How to print the ASP.NET scheduler from the browser. Uses the scheduler PNG export feature to create a special page with the print layout.
Apr 25, 2014
asp.net scheduler printing

Tutorial

Features

  • ASP.NET scheduler control displaying resources (Resource A, Resource B, ...)
  • Custom print page layout (the scheduler is exported to PNG)
  • Event creating using drag and drop (modal dialog)
  • Uses "White" CSS theme
  • SQL Server database (LocalDB)
  • Visual Studio 2012 solution included
  • C# source code
  • VB source code

Scheduler Print Page Layout

The scheduler is printed using a simple aspx page. The print page contains:

  • Header created using <h2> element
  • Scheduler image created using <asp:Image> control
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Print.aspx.cs" Inherits="_Print" MasterPageFile="~/Site.master" Title="Event Calendar with Day/Week/Month Views" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
  <link href='css/main.css' type="text/css" rel="stylesheet" /> 
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

  <h2>Print</h2>

  <div>
    <asp:Image runat="server" ID="ImageScheduler" />
  </div>

  <script type="text/javascript">
    window.print();
  </script>

</asp:Content>

Include the scheduler image using <asp:Image> control.

<asp:Image runat="server" ID="ImageScheduler" />

Set the image URL in the code behind:

C#

protected void Page_Load(object sender, EventArgs e)
{
  DateTime start = Convert.ToDateTime(Request.QueryString["start"]);
  int scrollX = Convert.ToInt32(Request.QueryString["scrollx"]);
  int scrollY = Convert.ToInt32(Request.QueryString["scrolly"]);
  ImageScheduler.ImageUrl = "Png.aspx?start=" + start.ToString("s") + "&scrollx=" + scrollX + "&scrolly=" + scrollY;
}

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  Dim start As Date = Convert.ToDateTime(Request.QueryString("start"))
  Dim scrollX As Integer = Convert.ToInt32(Request.QueryString("scrollx"))
  Dim scrollY As Integer = Convert.ToInt32(Request.QueryString("scrolly"))
  ImageScheduler.ImageUrl = "Png.aspx?start=" & start.ToString("s") & "&scrollx=" & scrollX & "&scrolly=" & scrollY

End Sub

You can invoke the browser print dialog using window.print() JavaScript method.

The sample project (Visual Studio 2012) including VB.NET and C# source code is available for download.

DayPilot for JavaScript, ASP.NET WebForms, ASP.NET MVC, Java