Solved

Javascript Print Function error

Posted on 2011-02-15
8
596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
ID: 34898446
try:

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

Accepted Solution

by:
Huseyin KAHRAMAN 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
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 55

Expert Comment

by:Huseyin KAHRAMAN
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 55

Expert Comment

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

Author Closing Comment

by:kdeutsch
ID: 34899248
Thanks
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

687 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