Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to print asp panel but when i call js function from code behind it gives me this error

JavaScript runtime error: Unable to get property 'getElementsByTagName' of undefined or null reference

how to solve this error????



my script is

XML
<script>

function printform()
        {

            var printContent = document.getElementById('<%= PNL_PrxStatus.ClientID %>');
             var btn = printContent.getElementsByTagName("input");

             var windowUrl = 'about:blank';
             var uniqueName = new Date();
             var windowName = 'Print' + uniqueName.getTime();
             var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=0,height=0');

             printContent.setAttribute("Position", "absolute");
             printContent.setAttribute("Top", "1291px");
             printContent.setAttribute("Left", "1341px");
             btn[0].style.display = 'none';

             printWindow.document.write(printContent.innerHTML);
             printWindow.document.close();
             printWindow.focus();
             printWindow.print();
             printWindow.close();
     }


</script>


and my code behide is this


ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "PrintForm", "printform();", true)


thnx in advance....
Posted

1 solution

TRY THIS,,,,, :)


JavaScript
Page.ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "printform();", true);
 
Share this answer
 
Comments
jagdish123061 2-Jul-13 2:29am    
Thanx for the reply... It is running successfully but not printing form it opens new window and then closes without print dialog .
jagdish123061 2-Jul-13 3:07am    
If I call printform() on button's onclientclick event then it prints form once then it is not printing form again I have to log out and log in again....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900