This is a migrated thread and some comments may be shown as answers.

radpane close after print

1 Answer 44 Views
Splitter
This is a migrated thread and some comments may be shown as answers.
Bart Reekmans
Top achievements
Rank 1
Bart Reekmans asked on 04 Feb 2013, 09:40 AM
Hi,

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;
                       pane.Print();
                   }                    }
               }

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 05 Feb 2013, 11:53 AM
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())
    {
        try
            var t = function() {
                previewWnd.print();           
            }
            setTimeout(t, 1000); // wait until the content is loaded
  
        } catch(e) {}
        return;   
    }
  
    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.document.open();
    previewWnd.document.write(popupContent);
    previewWnd.document.close();
  
    previewWnd.print();
    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).

Regards,
Vesi
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.
Tags
Splitter
Asked by
Bart Reekmans
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or