We help IT Professionals succeed at work.

Asp.Net C# 3.5 Web Applications:- Need to print the asp:Image control IMAGE only from my web application

chrisdtrinityphysicians
on
Medium Priority
653 Views
Last Modified: 2012-05-12
Hi,

    In my web application, I have 3 asp:Image controls and 3 asp:LinkButton controls.
 
     The 3 asp:Image controls are getting the ImageURL dynamically from code (Note: The images are available (saved) at file server hard disk).

     The 3 asp:LinkButtons are used to print the asp:Image control's image. This is how?

Note:-
     The same page has many designs, colors and other display items. But I want to print the particular image only. How?
Comment
Watch Question

You can print the Image using the corresponding link button, for this you need to place all images in different div or panel. eg. your aspx should look like as attached code


<script language=javascript>
function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 prtContent.innerHTML=strOldOne;
}
</script>

 
<div id="div1"><asp:Image ID="img1" runat="Server" />
<div id="div2"><asp:Image ID="img2" runat="Server" />
<div id="div3"><asp:Image ID="img3" runat="Server" />

<asp:HyperLink ID="hp1" runat="Server" onClick="javascript:CallPrint('div1');" />
<asp:HyperLink ID="hp2" runat="Server" onClick="javascript:CallPrint('div2');" />
<asp:HyperLink ID="hp3" runat="Server" onClick="javascript:CallPrint('div3');" />

Open in new window

Hi ajaysharmaapjs,

    Your Comment ID: 37077054 is requried to me. Here I have some doubts.

(1) prtContent.innerHTML=strOldOne;   Can you explain this? This line is required or not? If required, what is strOldOne?.

(2) Now on time being, temprorarly I ignored the line "prtContent.innerHTML=strOldOne;" only and tried with remaining lines. This is working fine in the browsers IE 9, Mozilla Firefox 7 and Nestscape Navigator 9.

But it is not working in the following browsers.

(3) Opera 11. Here I can't get the print dialogbox.

(4) Google Chrome 16. Here I can get the print dialogbox and print. But the print out page is blank. It contains only page header and footers. No contents.

(5) Apple Safari 5. Here also I can get the print dialogbox and print. But the print out page is blank. It contains only page header and footers. No contents.

Please give some tips to solve the issues (3), (4) and (5).

Note:- Here (5) is very important requirement to me.
I will check these issues n get back.
Hi ajaysharmaapjs,

      Can you attent this question...?
Hi ajaysharmaapjs,

      Can you attent this...?
hi, i am just working on your code, will post something relevant in a few minutes.
Ok I have made some changes in the script and code. Use below code:

<script language="javascript" type="text/javascript">
        function CallPrint(strid)
        {
            var prtContent = document.getElementById(strid);
            var WinPrint = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(prtContent.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();          
        }
    </script>


<div id="div1"><asp:Image ID="img1" runat="Server" ImageUrl="~/images/StorageAreaIcon1.png" /></div><br />
    <div id="div2"><asp:Image ID="img2" runat="Server" ImageUrl="~/images/StorageAreaIcon2.png" /></div><br />
    <div id="div3"><asp:Image ID="img3" runat="Server" ImageUrl="~/images/StorageAreaIcon3.png" /></div><br /><br />

    <asp:HyperLink ID="hp1" runat="Server" onClick="javascript:CallPrint('div1');" Text="Print 1" /><br />
    <asp:HyperLink ID="hp2" runat="Server" onClick="javascript:CallPrint('div2');" Text="Print 2" /><br />
    <asp:HyperLink ID="hp3" runat="Server" onClick="javascript:CallPrint('div3');" Text="Print 3" />

Open in new window


I have checked this code in IE, Firefox,Chrome, Safari and its working fine in these browsers.
But not able to get it working on the Opera.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.