Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi sir

I need to print text box value and barcode in asp.net. I am using the below code.the barcode display correct but text box value is clear.

What I have tried:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>

<script language="javascript" type="text/javascript">

if (window.print) {
document.write('<form><input type=button name=print value="Print" ></form>');
}


function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Get the HTML of whole page
var oldPage = document.body.innerHTML;

//Reset the page's HTML with div's HTML only
document.body.innerHTML = "<html><head> </head><body>" + divElements + "</body>";

//Print Page
window.print();

//Restore orignal HTML
document.body.innerHTML = oldPage;


}
</script>
</head>
<body>
<form id="form1" runat="server">





<asp:Label ID="Label1" runat="server" Text="no"><asp:TextBox ID="TextBox1" runat="server">

<asp:Label ID="Label2" runat="server" Text="bnb"> <asp:TextBox ID="TextBox2" runat="server">

<asp:Label ID="Label3" runat="server" Text="hjh"><asp:TextBox ID="TextBox3" runat="server">

<asp:Label ID="Label4" runat="server" Text="bar"><telerik:RadBarcode runat="server" ID="RadBarcode1" Type="Code11" Text="123" Font-Size="16px"
LineWidth="4" Height="32px" Style="margin-left: 75px" Width="131px" ShowChecksum="False"
ShowText="False">




<asp:Button ID="Button2" runat="server" Text="Print" OnClientClick=" javascript:printDiv('importDiv')" />
</form>
</body>
</html>
Posted
Comments
Sinisa Hajnal 10-Mar-16 2:33am    
Do you know that CSS can create your print page without DOM manipulation? Use @media print and simply hide the elements of the original page when printing.

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