Asp. NET page printing (20041117)
A system will certainly have a report or query, then it means to use the print, and ASP.net page print how to achieve it? Through my practice, summed up as follows:
1. Crystal Report
Advantages: Powerful, flexible to define the report.
Disadvantages: Not easy to deploy (transplant inconvenient, need to refer to components and input licenet, etc.), to achieve cumbersome
Implementation: First establish the report (. rpt file) and place a Crystalreportviewer control on the page you want to print, assigning the report source to the page control before printing.
2. Print the page
Advantages: Simple to implement and easy to use.
Disadvantage: page settings are not flexible.
Implementation: Passing parameters to the printed page (preset report style) when printing and display the data you want to print, and then press "print" directly in the toolbar. But by default, when printed with a header and footer, you want it to be taken off when printing (of course you can manually set it, if the customer wishes), There are two ways to implement a program, but it must be a client code implementation, because if the service-side code is implemented, the settings for the server will be modified as follows:
A. Modifying the Registry
<script language= "JavaScript" >
var Hkey_root,hkey_path,hkey_key;
Hkey_root= "HKEY_CURRENT_USER";
Hkey_path= "Software//microsoft//internet explorer//pagesetup//";
Set page header to print with empty headers and footers
function Pagesetup_null ()
{
Try
{
var wsh=new activexobject ("Wscript.Shell");
hkey_key= "Header";
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "");
hkey_key= "Footer";
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "");
}
catch (e) {}
}
Set the page header footer to be printed by default
function Pagesetup_default ()
{
Try
{
var wsh=new activexobject ("Wscript.Shell");
hkey_key= "Header";
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "&w&b page number, &p/&p");
hkey_key= "Footer";
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "&u&b&d");
}
catch (e) {}
}
</script>
After you set up the above two functions, click on the print to call the corresponding function.
B. Using ActiveX controls
There is a Scriptx.cab control on the Internet, the function of which can call the "Page Setup" dialog box to set up, detailed instructions can be obtained from the Internet, did not do the test.
However, both of the above methods will need to set the IE security level to the minimum.