add print function

2 posts, 0 answers
  1. beeta one
    beeta one avatar
    63 posts
    Member since:
    Aug 2012

    Posted 18 Jan 2013 Link to this post

    How to add print functionality in radcalendar? 
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Jan 2013 Link to this post

    Hi,

    Try the following code snippet to achieve your scenario.

    ASPX:
    <asp:LinkButton ID="LinkButton1" runat="server" type="button" Text="[ Print Calendar ]" OnClientClick="PrintRadCalendar(); return false;" Font-Underline="false" ForeColor="Black" />
    <telerik:RadCalendar ID="RadCalendar1" runat="server" Skin="Simple" MultiViewColumns="2" Style="margin-left: auto; margin-right: auto" MultiViewRows="2">
    </telerik:RadCalendar>

    JS:
    <script type="text/javascript">
        function getOuterHTML(obj) {
            if (typeof (obj.outerHTML) == "undefined") {
                var divWrapper = document.createElement("div");
                var copyOb = obj.cloneNode(true);
                divWrapper.appendChild(copyOb);
                return divWrapper.innerHTML
            }
            else
                return obj.outerHTML;
        }
      
        function PrintRadCalendar() {
            var previewWnd = window.open('about:blank', '', '', false);
            var sh = '<%= ClientScript.GetWebResourceUrl(RadCalendar1.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Calendar.{0}.css",RadCalendar1.Skin)) %>';
            var shBase = '<%= ClientScript.GetWebResourceUrl(RadCalendar1.GetType(),"Telerik.Web.UI.Skins.Calendar.css") %>';
            var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
            styleStr += "<link href = '" + shBase + "' rel='stylesheet' type='text/css'></link></head>";
            var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= RadCalendar1.ClientID %>').get_element().parentNode) + "</body></html>";
            previewWnd.document.open();
            previewWnd.document.write(htmlcontent);
            previewWnd.document.close();
            previewWnd.print();
            previewWnd.close();
        }
    </script>

    Hope this helps.

    Regards,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top