Solved

Javascript Print Function error

Posted on 2011-02-15
8
569 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
Comment Utility
try:

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

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
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
Comment Utility
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
 
LVL 2

Expert Comment

by:cookiej
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
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
Comment Utility
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
Comment Utility
good, then where is my points :)
0
 

Author Closing Comment

by:kdeutsch
Comment Utility
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now