Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In asp.net website application I want to print a specific part with out side link of the master page please give me the complete code .............


I want to print a textfile in div part
Posted

Put the content to be printed inside the div tag
Your Content


Then write the Javascript function which will take the name of this div as input and then will print it.

JavaScript
function CallPrint(var strid)
{
	var prtContent = document.getElementById(strid);
	alert(prtContent);
	var WinPrint = window.open('','','letf=10,top=10,width="450",height="250",toolbar=1,scrollbars=1,status=0');

	WinPrint.document.write("<html><head><link rel="\"stylesheet\"" href="\"css/print.css\"" media="\"print\""><link rel="\"stylesheet\"" href="\"css/print.css\"" media="\"screen\""></head><body>");

	WinPrint.document.write(prtContent.innerHTML);
	WinPrint.document.write("</body></html>");
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
	WinPrint.close();

	return false;
}</link></link>


Call CallPrint('printDiv');" on onclick() of button or use below:
C#
Button.Attributes.Add("OnClick", "return CallPrint('printDiv');");


Here Button referes to the name of the button on click of which you want to print the content.

Hope this helps.
All the best.
 
Share this answer
 
Comments
Shibiny 14-Oct-11 6:56am    
Sorry it is not working

iwant to print a apllication form that contain text box and label within a table tag ind in a panel
code
<asp:Panel ID="panel2" runat="server">
<table style="width: 100%">

<tr><td></td><td >

You Have Applied Successfully!

</td></tr>
<tr>
<td style="padding-left: 100px; text-align: left;font-size:small">
 </td>
<td style="padding-left:0px"><asp:Image ID="imgphoto" runat="server" Height="110px" Width="120px" /></td>
</tr>
<tr>
<td style="padding-left:100px; text-align: left;font-size:small">
 </td>
</tr>
<tr>
<td style="padding-left: 100px; width: 40%; text-align: left;font-size:small">
Name of Applicant</td>
<td style="width: 60%; text-align: left;font-size:small">
<asp:Label ID="lblfname" runat="server" Text="">  <asp:Label ID="lbllname"
runat="server" Text="">
 </td>
</tr>

<tr>
<td style="padding-left: 100px; width: 40%; text-align: left;font-size:small">
 </td>
<td style="width: 60%; text-align: left;font-size:small">
 </td>
</tr>
<tr>
<td style="padding-left: 100px; width: 40%; text-align: left;font-size:small">
Age</td>
<td style="width: 60%; text-align: left;font-size:small">
<asp:Label ID="lblage" runat="server" Text="">
</td>
</tr>
<tr>
<td style="padding-left: 100px; width: 40%; text-align: left;font-size:small">
<asp:Label ID="lblquali" runat="server" Font-Bold="True" Font-Size="Medium"
Text="Qualification">
</td>
<td style="width: 60%; text-align: left;font-size:small">
 </td>
</tr>
</table>






<table border="1">
<tr>
<td align="center" style="border-style: solid" width="2px">
SI NO</td>
<td align="center" style="border-style: solid" width="2px">
Qualification</td>
<td align="center" style="border-style: solid">
Year
</td>
<td align="center" style="border-style: solid">
%</td>
<td align="center" style="border-style: solid" width="2px">
Board</td>
</tr>
</table>
If u want to print a particular div, it will help you

<a href="#" önclick="javascript:printdiv();">Print</a>


XML
function printdiv()
    {
    var divToPrint=document.getElementById('<%=DivPrint.ClientID %>');
        var newWin=window.open('pagename.aspx','PrintWindow');
    newWin.document.open();
    newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
    newWin.document.close();
    }
 
Share this answer
 
v2
Comments
Shibiny 14-Oct-11 6:57am    
Sorry it is not working
 
Share this answer
 

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