Click here to Skip to main content
15,884,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,
I have a aspx page, with data in the text boxes, and also a button "confirm" which onclick adds it to the database. I want to add a another button, which prints the entire page as a bill(as in my application).
I tried using onclick="window.print();" but i was ended with a server error.
So can you suggest the solution.

Thanks & Regards
Rajani
Posted
Comments
ZurdoDev 19-Mar-13 7:04am    
What was the error?
raj_arenem 19-Mar-13 8:02am    
Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1026: ) expected

Source Error:



Line 167: <asp:Button ID="Button3" runat="server" Text="Confirm"
Line 168: onclick="Button3_Click" Width="120px" />
Line 169: <asp:Button ID="Button1" runat="server" Text="Button" OnClick="window.print();" />
Line 170:
Line 171: </td>

ZurdoDev 19-Mar-13 8:05am    
You need to use OnClientClick because this is an ASP.Net button. OnClick is actually the method in C# that you want to run but window.print() is in javascript so you need to use OnClientClick instead.
raj_arenem 20-Mar-13 0:56am    
Thank you sir. Its working.
:)...
ZurdoDev 20-Mar-13 7:05am    
Good to hear.

You need to use OnClientClick because this is an ASP.Net button. OnClick is actually the method in C# that you want to run but window.print() is in javascript so you need to use OnClientClick instead.
 
Share this answer
 
HTML
<!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 runat="server">
    <title>Untitled Page</title>
    <style media="print" type="text/css">
    #printButton { display: none; }
    #pageHeader { display: none; }
    #pageFooter { display: none; }
    </style>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="button" onblur="window.print();" id="printButton" value="Print Page" />
    <p id="pageHeader">Transaction Summary</p>
    <p>This is some page.</p>
    </div>
    <p id="pageFooter">footer stuff</p>
    </form>
</body>
</html>
 
Share this answer
 
v3

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