radpane close after print

2 posts, 0 answers
  1. Bart Reekmans
    Bart Reekmans avatar
    26 posts
    Member since:
    Mar 2010

    Posted 04 Feb 2013 Link to this post


    We're using the following code to print the content of a radpane :
    But the newly opened window does not close itself after printing.
    Is there any way to achieve this behaviour?
    function clientButtonClicking(sender, args) {
                       var toolBar = sender;
                       var button = args.get_item();
                       if (button.get_value() == "print") {
                           var splitter = $find('<%= RadSplitter2.ClientID%>');
                           var pane = splitter.GetPaneById('<%= RadPaneContentDetail.ClientID %>');
                           if (!pane) return;
                       }                    }
  2. Vessy
    Vessy avatar
    1886 posts

    Posted 05 Feb 2013 Link to this post

    Hi Chris,

    By design the RadPane's print() method is implemented on the base of the default window.print() method.

    Unfortunately, it does not dispose a way to access (and respectively to close) the opened print window. The only possible way to achieve it is by overwriting the RadPane's print() by adding the desired closing functionality.

    For instance, you could achieve it in a similar way:
    Telerik.Web.UI.RadPane.prototype.print = function(arrCssFiles)
        /// <summary>
        /// print the content of the pane. If the pane is not displaying
        /// external content the printed content will be formatted using the specified cssFiles.
        /// </summary>
        var sFeatures = 'width=' + this.get_width() + 'px, height=' + this.get_height() + 'px, scrollbars=1';
        var previewWndUrl  = (this.isExternalContent()) ? this.get_contentUrl() : 'about:blank' ;
        var previewWnd = window.open(previewWndUrl, '', sFeatures, false);
        if (this.isExternalContent())
                var t = function() {
                setTimeout(t, 1000); // wait until the content is loaded
            } catch(e) {}
        var styleStr = "";
        if (arrCssFiles) {
            styleStr = "<head>";
            for(var i=0, length=arrCssFiles.length; i < length; i ++)
                styleStr += "<link href = '" + arrCssFiles[i] + "' rel='stylesheet' type='text/css'></link>"
            styleStr += "</head>";
        var popupContent = styleStr + "<body>" + this.get_content() + "</body>"
        previewWnd.onfocus = function(){previewWnd.close()};

    Please, note that the script, which is overwriting the RadPane's print() function, has to be placed inside the <form> tag (recommended just before the closing </form> tag).

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top