Classic ASP. NET Printing Technology

Source: Internet
Author: User

For B/S architecture projects, Web printing is the technology that gives programmers a headache. In this project, a third-party control ScriptX is used to solve this technology, including various summary tables and detailed lists, but the biggest drawback is that the print format is dead. You have to print out the format by yourself, and print the page, which is based on the size of the paper you set, therefore, manual control is required. The ScriptX file is required for the ScriptX control. cab. (ScriptXhttp: // www.meadroid.com/scriptx/freedep.asp)
Print function usage:
 
(1) The user clicks the "print" button on the client. The following dialog box is displayed when "print" is used for the first time.
 
(2) Click the "yes" button and the control ScriptX will be downloaded to the local machine.
 
(3) In the print window, there are large titles, print conditions, and print lists. Click the print button to enter the print browsing interface.
 
(4) Click the Print button to hear the printer sound.
2. Use an instance of a simple ScriptX Control
1. The interface file WebExample. aspx (in which kg.css is the interface style is not described here)

Reference content is as follows:
<% @ Page language = "c #" Codebehind = "WebExample. aspx. cs" AutoEventWireup = "false" Inherits = "WebPrint. WebExample" %>
<〈! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<Title> A simple ScriptX print </title>
<Meta name = "GENERATOR" Content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "CODE_LANGUAGE" Content = "C #">
<Meta name = "vs_defaultClientScript" content = "JavaScript">
<Meta name = "vs_targetSchema" content = "http://schemas.microsoft.com/intellisense/ie5">
<LINK href = "kg.css" type = "text/css" rel = "stylesheet">
</HEAD>
<Body MS_POSITIONING = "GridLayout">
<Form id = "WebExample" method = "post" runat = "server">
<TABLE width = "100%" height = "100%">
<Tr>
& Lt; td height = "100" & gt;
</Td>
</Tr>
<Tr>
<Td style = "HEIGHT: 14px" align = "center">
<Div id = "divTableResult" name = "divTableResult">
<Asp: Label id = "Label1" runat = "server" Width = "232px" Height = "32px" Font-Size = "Large"> welcome to ScriptX printing </asp: label>
</Div>
</Td>
</Tr>
<Tr>
<Td align = "center" valign = "top">
<Div id = "divChartResult" name = "divChartResult">
<Asp: Image id = "Image1" runat = "server" ImageUrl = "win2000.gif"> </asp: Image>
</Div>
</Td>
</Tr>
<Tr>
<Td align = "center" valign = "top">
<Input id = "btnPrint" style = "WIDTH: 32px; HEIGHT: 19px" onclick = "printResult ();" type = "button"
Size = "1" value = "print" name = "btnPrint">
</Td>
</Tr>
</TABLE>
</Form>
<Script language = "javascript">
Function printResult ()
{
// Set print parameters for different modules
Var title = 'scriptx print'; // report name
Var orien = 'true'; // print the page direction; true: vertical print/false horizontal print
// The parameter settings are complete.
Var strURL;
Title = escape (title );
// Condition = escape (condition );
StrURL = 'printcontainer2. aspx? Title = '+ title +' & orien = '+ orien;
Window. open (strURL, 'printresresult', 'height = 600, width = 800, top = 0, left = 50, toolbar = no, menubar = no, scrollbars = yes, resizable = no, location = no, status = no ');
}
</Script>
</Body>
</HTML>

Note:

Reference content is as follows:
(1) <div id = "divTableResult" name = "divTableResult"> and <div id = "divChartResult" name = "divChartResult"> are value passing labels defined in the printContainer2.aspx file, therefore, you must have one.
(2) The printResult () method is used to declare the content of the passed value. The details are described in the method.

 

2. Print the page printContainer2.aspx (in which print.css is a print style is not introduced)
<% @ Page language = "c #" Codebehind = "printContainer2.aspx. cs" AutoEventWireup = "false" Inherits = "WebPrint. printContainer2" %>
<〈! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<%
String title = "query printing ";
'Used to obtain the title
If (Request. QueryString ["title"]. ToString (). Trim ()! = ""){
Title = Request. QueryString ["title"]. ToString (). Trim ();
}
'Is used for orientation to obtain the direction of the printed page. true: vertical print/false horizontal print
String orientation = "true ";
If (Request. QueryString ["orien"]. ToString (). Trim ()! = ""){
Orientation = Request. QueryString ["orien"]. ToString (). Trim ();
}
%>

Reference content is as follows:
<Html>
<Head>
<Title> ScriptX printing </title>
<Meta name = "GENERATOR" Content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "CODE_LANGUAGE" Content = "C #">
<Meta name = "vs_defaultClientScript" content = "JavaScript">
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
<Meta name = "vs_targetSchema" content = "http://schemas.microsoft.com/intellisense/ie5">
<Link href = "kg.css" rel = "stylesheet" type = "text/css">
<Link href = "print.css" rel = "stylesheet" type = "text/css" media = "print">
<Script FOR = document event = "onclick">
If (event. srcElement. tagName = 'A '){
// Alert ('a click! ');
Event. cancelBubble = true;
}

 

</Script>

<Style type = "text/css">
A: link {text-decoration: none}
A: visited {text-decoration: none}
A: active {text-decoration: none}
A: hover {text-decoration: none}

A {COLOR: #000000; TEXT-DECORATION: none; FONT-SIZE: 8pt; FONT-FAMILY :"";}

</Style>
</Head>

<Body MS_POSITIONING = "GridLayout">
<〈! -- Call the control ScriptX. cab -->
<Object id = "factory" viewastext style = "display: none"
Classid = "clsid: 1663ed61-23eb-11d2-b92f-008048fdd814"
Codebase = "ScriptX. cab # Version = 6, 1, 431,2">
</Object>
<SCRIPT defer>
// Set print Parameters
Function printBase (){
Factory. printing. footer = "& B ScriptX Print & B" // Header
Factory. printing. footer = "" // footer
Factory. printing. portrait = <%= orientation %> // true indicates vertical printing, and flase indicates horizontal printing.
Factory. printing. leftMargin = 1.5 // left margin
Factory. printing. topMargin = 0.5 // top margin
Factory. printing. rightMargin = 0.5 // right margin
Factory. printing. bottomMargin = 1.0 // bottom margin
}
</SCRIPT>
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0" align = "center" bordercolor = "# FFFFFF">
<Tr bordercolor = "# FFFFFF">
<Td>
<Table width = "70%" border = "0" cellspacing = "0" cellpadding = "2" align = "center">
<Tr>
<Td align = "center"> <font size = "5" face = ""> <B> <div name = "divTitle" id = "divTitle"> </div> </B> </font> </td>
</Tr>
<Tr>
<Td align = "center">
<Div id = "divReport" name = "divReport">
<Input type = "button" name = "Export print" id = "Export print" onclick = "printReport ()" value = "print">

<Input type = "button" onclick = "window. close ();" value = "close">
</Div>
</Td>
</Tr>
</Table>
</Td>
</Tr>
</Table>
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "2" align = "center">
<Tr> <td align = "center">
<〈! -- Used to display the divTableContainer tag value -->
<Div id = "divTableContainer" name = "divTableContainer"> </div>
</Td> </tr>
<Tr> <td align = "center">
<〈! -- Used to display the divChartContainer tag value -->
<Div id = "divChartContainer" name = "divChartContainer"> </div>
</Td> </tr>
</Table>
</Body>
<Script language = "javascript">
// Maximize the interface
MaxWin ();

Var needcon = '';
Document. all. divTitle. innerText = unescape ('<%= title %> ');

// The divTableResult and divChartResult labels of the parent form are transferred to the divTableContainer and divChartContainer labels respectively.
Var tableContent = too many opener.doc ument. all. divTableResult. innerHTML;
TableContent = replaceAll (tableContent, "<A", "<span ");
TableContent = replaceAll (tableContent, "</A>", "</span> ");
TableContent = replaceAll (tableContent, "<a", "<span ");
TableContent = replaceAll (tableContent, "</a>", "</span> ");
TableContent = replaceAll (tableContent, "<input", "<font ");
TableContent = replaceAll (tableContent, "<INPUT", "<font ");
Document. all. divTableContainer. innerHTML = tableContent;
Document. all. divChartContainer. innerHTML = too many opener.doc ument. all. divChartResult. innerHTML;

// Call the method for setting print parameters and display the preview Interface
Function printReport (){
PrintBase ();
// Window. print ();
Factory. printing. Preview ();
}
Function replaceAll (str, from, ){
Var idx = str. indexOf (from );
While (idx>-1 ){
Str = str. replace (from, );
Idx = str. indexOf (from );
}
Return str;
}
Function maxWin ()
{
Var aw = screen. availWidth;
Var ah = screen. availHeight;
Window. moveTo (0, 0 );
Window. resizeTo (aw, ah );
}
</Script>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.