Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Window > auto printing rad window content
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

auto printing rad window content

Feed from this thread
  • Yaniv Hanya Intermediate avatar

    Posted on Jun 28, 2007 (permalink)

    I"m trying to create "print" window using rad window.

    i used very simple method- load the text to the page, and calling window.print method, but it is not working. when i tried the page in the browser, the print function worked great, but in the radwindow it is not working.

    i tried this code:
    function GetRadWindow()
    {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
    }


    and then, after the "body" declaration:
    <script> 
    {  
    GetRadWindow().print()  

    and it didn't worked, so i tried the folow:
    var oWnd = GetRadWindow();     
    window.parent.frames[oWnd.Name].focus();      
    window.parent.frames[oWnd.Name].print();    
     


    and nothing happend...

    what do i do wrong?

  • Tervel Tervel admin's avatar

    Posted on Jun 29, 2007 (permalink)

    Hi Yaniv,

    The object returned by the GetRadWindow function is "not" a browser window object. It is the client  javascript representation of the RadWindow control. So - it does not feature a method for printing.

    Since the RadWindow content area is a simple IFrame, to print you should call the print method on the object that defines it - e.g. the iframe's content window.

    There are two ways to do it - one by using the RadWindow object, and second - by just calling print.

    e.g.:

    {  
    print() ;

    or

    <script> 
    {  
    GetRadWindow().GetContentFrame().contentWindow.print()  



    Best wishes,
    Tervel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Yaniv Hanya Intermediate avatar

    Posted on Jun 29, 2007 (permalink)

    Hi tervel, thank for the quick reply.

    both methods didn't worked for me, if i put it as "automatic" fuction (just throw the script after the "body" tag, nothing happen.
    i tried to put it in a funmction (e.g. function print()) and then call it, onload or by clicking button, in both cases i got "stack over flow"...

    did it worked in your side?

  • Georgi Tunev Georgi Tunev admin's avatar

    Posted on Jul 3, 2007 (permalink)

    Hi Yaniv,

    I've just tried the 2 suggestions that Tervel gave and they are working as expected - I have attached to this thread the sample code. Does the attached sample work for you?

    By the way if you are going to call the print() function "automatically", make sure that it will be called only when the whole page is loaded - e.g. window.onload = function(){......}

    If you still experience problems, please send us a support ticket with the problematic pages attached. We will check them and do our best to help.




    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
    Attached files

  • Yolanda avatar

    Posted on Jul 20, 2007 (permalink)

    I have the same problem and tried both and did not work....

    Also I am runing the new new window as modal... does it make the diference?

    The content of the RadWindows its a fedex label with other information and when I popoulate and then call the print it printed the window, the content inside and the blur background..... exactly what I see when Iam in front of the monitor.... is there any way to print ONLY the content of the RadWindow?

    this is the way I create the  child window that I need to print the content inside...

       var width  = 840;
       var height  = 450;
       var left  = (screen.width/2) - width/2;
       var top   = (screen.height/2) - height/2;
     
        var batchOrderUrl = "\BatchOrders.ashx?aid=" + BatchOrderID;  
        
       var oManager = GetRadWindowManager();
        var oWnd = oManager.GetWindowByName("wndBatchs");
        oWnd.Show();
        oWnd.SetSize(width,height);
        oWnd.SetUrl( batchOrderUrl );  
     

    Yolanda 

  • Georgi Tunev Georgi Tunev admin's avatar

    Posted on Jul 20, 2007 (permalink)

    Hello Yolanda,

    I believe the sample code attached to this forum post will be of help.




    Kind regards,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Yaniv Hanya Intermediate avatar

    Posted on Jul 20, 2007 (permalink)

    I couldn't make it in my side, i trid every thing in this posts and it didn't worked for me. i just created javascript function that open new browser window, print it and close it. it is not the best way, off course, since i have to reload the page, but nothing else done it. 

  • Yolanda avatar

    Posted on Jul 22, 2007 (permalink)

    I am creating like a report on a new window, with 1,2 or 10 orders along the content (with a scroll) and to improve efficiency I create a 

    public class BatchOrders : IHttpHandler {...}

    So everycode, every line, every char that I sent to the context is controlled, do I need to have any special code on this particular page?
    Remember that this page is the content of the modal window.
    I just see the file RadWindowClient.js and was thinking when or when not to load this file to include on that page.

  • Yolanda avatar

    Posted on Jul 22, 2007 (permalink)

    Yes Yaniv, thats how I had before, but I change it to radwindow to use the advantages of the .net component, if I read the content of the radwindow dialog and place into another window, that will not solve anything. Its hard but for somereason its not printing as it should does.

  • Georgi Tunev Georgi Tunev admin's avatar

    Posted on Jul 23, 2007 (permalink)

    Hello Yolanda, Yaniv,

    The problem with the printing comes from the way IE and Firefox work with IFRAMES. You will need to provide different Javascript for printing the content depending on the browser. Generally speaking, if you manage to achieve the desired functionality by using a standard IFRAME, the same solution will work with the RadWindow control.




    Kind regards,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • PaulMrozowski avatar

    Posted on Jan 18, 2008 (permalink)

     I thought I'd post a follow up to this, since it wasn't really resolved. The problem you'd run into if you try to open a RadWindow and auto-print the content is that, even using the code provided to get a reference to the iframe window, it would still print the full browser window with the iframe overlayed on top of it.

    If you place a button on the same pop-up form, and run the same exact code, it prints correctly - it was only auto-printing that seemed to cause the problem. Here's what I ended up with that finally worked:

    <script language='javascript'
        function GetRadWindow() 
        { 
            var oWindow = null
            if (window.radWindow) oWindow = window.radWindow; 
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 
            return oWindow; 
        }  
        window.onload = function()  
        {  
            GetRadWindow().GetContentFrame().contentWindow.focus();  
            GetRadWindow().GetContentFrame().contentWindow.print();  
        } 
    </script> 

    The secret seems to be setting focus to the window first. Hopefully this saves people some grief.

  • Soneliso Ngwane avatar

    Posted on Jul 29, 2009 (permalink)

    Thanks, i had the same problem but now its working hundrends..

    Thank you

  • Posted on May 19, 2011 (permalink)

    Great post PaulMrozowski,  I've been having a similar problem which is not quite the same.  I have a list of printable vouchers, you can click on 1 which then opens the rad window, which will display just that voucher and a print button.

    Clicking the print button should initiate the print dialog, which it does in FF, Chrome etc but NOT in IE8, very strange. Does IE and FF see rad windows differently?  Here is my code for when the user clicks the print button.

    Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnPrint.Click
            'Now we need to add the print option to the button
            'Now print the page
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "popup", "PrintMe1();", True)
            UpdateUseage()
            
             
        End Sub
    and of course my javascript function.

    function PrintMe1() {
                    GetRadWindow().GetContentFrame().contentWindow.focus();
                    GetRadWindow().GetContentFrame().contentWindow.print();
                }

    Can anyone shed any light?

  • Marin Bratanov Marin Bratanov admin's avatar

    Posted on May 20, 2011 (permalink)

    Hi Stephen,

    I would recommend including that function in the RadWindow statically and moving the printing functionality to the client-side, as it is possible that not all controls are loaded at the point the script tries to execute. Besides, this functionality is not related to the server in any way, it is pure client-side.

    I believe that you may find the followin KB article useful: http://www.telerik.com/support/kb/aspnet-ajax/window/adding-a-custom-button-to-radwindow-titlebar.aspx. Note that the document object is used as a first choice. This KB will also show you how to add the button to the titlebar (you may use your own, prettier sprite, though ;) ).

    If this article does not help you resolve the situation please open a support ticket and send us a sample project that isolates your issue so we can investigate it locally and provide a more to the point answer.



    Best wishes,
    Marin
    the Telerik team

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

  • Posted on May 23, 2011 (permalink)

    thanks for the reply and the link, i have looked at that example but i have a slighly diefffernt requirement.  I need to submit to the database a record of when the user clicks the submit button on the rad window popup then if that is successfull trigger the print from code behind.  What i dont understand is that it works fine in FF, Chrome etc but not IE.

    You can see this working on the following development link here

    You can use my login details to test

    stephen@lateralline.co.uk
    test

    Thanks..

    S


  • Marin Bratanov Marin Bratanov admin's avatar

    Posted on May 24, 2011 (permalink)

    Hi Stephen,

    The approach from the KB article works for Firefox and IE as well. The issue I see when opening the site is that there are JavaScript errors thrown and, without having your actual code, I must assume that this is the reason why IE breaks the execution and you do not get the printing window, while Firefox just swallows it and tries to go on.

    What I can suggest at this point is to try clearing these errors from your site and testing again. You can also try using the ScriptManager's RegisterStartUpScript() method instead, especially in case you are using AJAX on the page.

    Another possible issue is that the controls and content might not be loaded when you try to execute the script you inject from the server-side. To confirm that  you could try the suggestions from the following blog post on the matter: http://blogs.telerik.com/supportdept/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx.



    Greetings,
    Marin
    the Telerik team

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

    Attached files

  • Posted on May 24, 2011 (permalink)

    thanks Marin for your reply, those JS errors related to a missing JS file which is now in place and there are now NO errors.

    I will have a look at your 2nd link below and test if the content is loaded. Also just to confirm that IF i use window.close JS function then the code fires without issue.

    Regards,

    S

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Window > auto printing rad window content