• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

Javascript Print Function error

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
kdeutsch
Asked:
kdeutsch
  • 4
  • 3
1 Solution
 
HainKurtSr. System AnalystCommented:
try:

var content = document.getElementById('pnlProblems');
-->
var content = document.getElementById('<%=pnlProblems.ClientID%>');
0
 
HainKurtSr. System AnalystCommented:
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
 
kdeutschAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
cookiejCommented:
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
 
HainKurtSr. System AnalystCommented:
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
 
kdeutschAuthor Commented:
hainkurt,

you had it correct originally i just forgot to change my content from Content.  Once I did this it worked fine.
0
 
HainKurtSr. System AnalystCommented:
good, then where is my points :)
0
 
kdeutschAuthor Commented:
Thanks
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now