[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Javascript Print Function error

Posted on 2011-02-15
8
Medium Priority
?
612 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 60

Expert Comment

by:HainKurt
ID: 34898446
try:

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

Accepted Solution

by:
HainKurt earned 2000 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 60

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 60

Expert Comment

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

Author Closing Comment

by:kdeutsch
ID: 34899248
Thanks
0

Featured Post

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.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Suggested Courses

656 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