7
Answers

How to print html div or table from user control in asp.net

Manoj Patel

Manoj Patel

8y
595
1

Dear Experts,

I'm facing a problem with ASPX user control,

I have design a html in user control

I wish to print their html design (html div or table), have added JavaScript as below, but this JavaScript not working in user control

<script type="text/javascript">
function PrintDiv() {
var divContents = document.getElementById("Print_Div").innerHTML;
var printWindow = window.open('', '', 'height=200,width=400');
printWindow.document.write(divContents);
printWindow.document.close();
printWindow.print();
}
</script>

----------------------

<input type="button" onclick="PrintDiv();" value="Print" />

then i have modify this code as below

<asp:Button id="btnPrint" runat="server" OnClientClick="PrintDiv();" text="Print Me" OnClick="btnPrint_Click" />

In code behind

protected void btnPrint_Click(object sender, EventArgs e)
{
btnPrint.Attributes.Add("onclick", "PrintDiv();");
}


Still not working

Please help us.


Answers (7)