Close on Click

3 posts, 1 answers
  1. Robert Bross
    Robert Bross avatar
    27 posts
    Member since:
    Oct 2012

    Posted 07 Jul 2008 Link to this post

    I am using a RADMenu that is inside of a RADWindow. What I want is to have a print menu option that would print the contents of the RADWindow. What is happening though is that the Menu gets included on the printout because it isnt closing when I click the print menu item. I tried using the close method of the menu but that isnt working. What do I need to do to accomplish this?

    Thanks!

    ========== Parent Page ======================
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <html><body><form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <telerik:RadWindow ID="RadWindow1" runat="server" NavigateUrl="TestPrintMenu_SubPage.aspx" VisibleOnPageLoad=true></telerik:RadWindow>
    </form></body></html>


    =========== Sub Page with Menu ================

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <html>
    <script type="text/javascript">
        function printWindow(){
            var menu = $find("mainMenu");
            menu.close();
            window.print();}
    </script>
    <body><form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadMenu ID="mainMenu" runat="server" Skin="Vista" ClickToOpen="True">
                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                    <Items>
                        <telerik:RadMenuItem runat="server" Text="File">
                            <Items>
                                <telerik:RadMenuItem runat="server" NavigateUrl="javascript: printWindow();" Text="Print"></telerik:RadMenuItem>
                                <telerik:RadMenuItem runat="server" IsSeparator="True" Text="-"></telerik:RadMenuItem>
                                <telerik:RadMenuItem runat="server" Text="Close"></telerik:RadMenuItem>
                            </Items>
                        </telerik:RadMenuItem>
                    </Items>
        </telerik:RadMenu>
    </form></body></html>

  2. Answer
    Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 Jul 2008 Link to this post

    Hi Robert,

    RadMenu's close() method will close the expanded item, but it will not hide the menu. To achieve the desired result, I suggest the following solution:

    <script type="text/javascript">  
        function printWindow(){  
            var menu = $find("mainMenu");             
            menu.close();         
            var menuDivElement = $get("mainMenu");     
            menuDivElement.style.display = "none";  
            //setTimeout is used to fix a problem with Firefox  
            setTimeout('javascript:window.print()', 500);  
            }  
    </script> 


    Kind regards,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Robert Bross
    Robert Bross avatar
    27 posts
    Member since:
    Oct 2012

    Posted 08 Jul 2008 Link to this post

    Thanks for the help. This didnt do exactly what I wanted it to do, but pointed me in the right direction. The code sample below actually hides the entire menu which is not what I need. I needed it to just "Collapse" the file menu. So, expanding upon the code sample provided, I am using that to call another function which prints the window and then reshows the menu. It works good.

    Thanks for your help!

    =========== Updated Code Sample ==================

    function

    printWindow(){

    var menu = $find("mainMenu");
    menu.close();

    var menuDivElement = $get("mainMenu");
    menuDivElement.style.display =
    "none";

    //setTimeout is used to fix a problem with Firefox
    setTimeout('actualPrintWindow()', 10);
    }

    function actualPrintWindow(){
    window.print();

    var menuDivElement = $get("mainMenu");
    menuDivElement.style.display =
    "block";
    }

Back to Top