Solved

Javascript Print Function error

Posted on 2011-02-15
8
575 Views
Last Modified: 2012-08-13
What I am trying to accomplish is to print the gridview that sits in a modal popup window,  I get an error though that my content is undefined. from this line.  My page is derived from a master page and i don't know if that is what would cause the problem. but its like ti cannot pass the gridview to the blank page.

 WinPrint.document.write(Content.innerHTML);

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <link href="../Readiness.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript">
       
        function printMe() {
            var content = document.getElementById('pnlProblems');
            var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(Content.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }

    </script>
</asp:Content>
Html panel
 <asp:Panel ID="pnlProblems" runat="server" CssClass="ModalWindow2" style="display:none">
                   <asp:LinkButton ID="lnkSee" runat="server" style="display:none"></asp:LinkButton>
                    <table width="100%">
                        <tr>
                            <td align="center"><asp:GridView ID="myGridProblems" runat="server" Font-Size="12pt" HeaderStyle-HorizontalAlign="Center" BorderWidth="1px"
                                CellPadding="6" BorderColor="#404040" Font-Names="Veranda,arial,sans-serif" AutoGenerateColumns="False"
                                Width="80%" RowStyle-HorizontalAlign="Center"><AlternatingRowStyle BackColor="#b0c4de" /><HeaderStyle Font-Bold="true" ForeColor="White"
                                BackColor="SteelBlue" />
                                <Columns>
                                    <asp:BoundField DataField="strCategory" HeaderText="Category" />
                                    <asp:BoundField DataField="strTask" HeaderText="Task" />
                                    <asp:BoundField DataField="bitAnswer" HeaderText="Status" />
                                </Columns>
                                </asp:GridView>
                             </td>
                        </tr>
                        <tr>
                             <td align="center"><asp:LinkButton ID="lnkProbCancel" runat="server">Next Soldier</asp:LinkButton>
                             &nbsp;&nbsp;&nbsp<asp:LinkButton ID="lnkCurrentRecord" runat="server">Return to Soldier</asp:LinkButton>
                             &nbsp;&nbsp;&nbsp;<input type="button" onclick="printMe()" /></td>
                        </tr>
                    </table>
                    <asp:ModalPopupExtender ID="pnlProblems_ModalPopupExtender" runat="server" Enabled="True" TargetControlID="lnkSee" PopupControlID="pnlProblems" BackgroundCssClass="modalBackground" />
                </asp:Panel>

Open in new window

0
Comment
Question by:kdeutsch
  • 4
  • 3
8 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34898446
try:

var content = document.getElementById('pnlProblems');
-->
var content = document.getElementById('<%=pnlProblems.ClientID%>');
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34898457
also

WinPrint.document.write(Content.innerHTML);
-->
WinPrint.document.write(content.innerHTML);

or just this:

var content = document.getElementById('pnlProblems');
-->
var Content = document.getElementById('<%=pnlProblems.ClientID%>');
0
 

Author Comment

by:kdeutsch
ID: 34898605
Hi,
Tried this but still smae error

 <script type="text/javascript" language="javascript">
       
        function printMe() {
            var content = document.getElementById('<%=pnlProblems.ClientID%>');
            var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(Content.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }

    </script>
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Expert Comment

by:cookiej
ID: 34898629
You also misspelled "left" in the line:

 var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34898665
try this:

<script type="text/javascript" language="javascript">
        function printMe() {
alert('<%=pnlProblems.ClientID%>'); // delete this line after testing
            var Content = document.getElementById('<%=pnlProblems.ClientID%>');
            var WinPrint = window.open('', '', 'left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(Content.innerHTML);
            // WinPrint.document.close(); // are you sure about this line?
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
</script>
0
 

Author Comment

by:kdeutsch
ID: 34899173
hainkurt,

you had it correct originally i just forgot to change my content from Content.  Once I did this it worked fine.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34899228
good, then where is my points :)
0
 

Author Closing Comment

by:kdeutsch
ID: 34899248
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question