简体   繁体   中英

To print entire aspx page using C#

I created a asp.net page containing labels grids etc.. it has

code:

<%@ Page Title="" Language="C#" MasterPageFile="~/App/MasterPage.master"  AutoEventWireup="true" CodeFile="ServiceCheckList.aspx.cs" Inherits="App_AutoRx_ServiceCheckList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="Server">
    <div class="container">
        <div class="row" style="box-shadow: 0px 1px 6px #808080 !important;">
            <div class="panel">
                <div class="panel-heading">
                    <h3 style="color: black;">Service Check List</h3>

                    <div style="text-align: right">
                        Date :
                        <asp:Label ID="lblDate" runat="server"></asp:Label>
                    </div>
                </div>
                <div class="panel-body">
                    <div>
                        Service Check List Code :
                        <asp:Label ID="lblSCLC" runat="server" Text="CSSC"></asp:Label>
                    </div>
                    <table id="tblbase" class="nav-justified" border="1" style="border: thin inset #999999">
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 35%; background-color: red; color: white">Customer Details</td>
                            <td style="width: 65%; background-color: red; color: white">Vehicle Details</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="panel-body">
                                    <table id="tblCustomer" class="nav-justified" style="column-width: inherit">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblForCustomerName" runat="server" Text="Customer Name:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblCustomerName" runat="server" Text="Suraj"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblForContactNo" runat="server" Text="Contact No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblContactNo" runat="server" Text="123456"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblForAlternateNo" runat="server" Text="Alternate No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblAlternateNo" runat="server" Text="scc-101"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforEmailId" runat="server" Text="Email Id:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblEmailId" runat="server" Text="scc-101"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforAddress" runat="server" Text="Address:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblAddress"  runat="server" Text="scc-101"></asp:Label></td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                            <td>
                                <div class="panel-body">
                                    <table id="tblvehicle" class="nav-justified" style="column-width: inherit">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforRegistrationNo" runat="server" Text="Registration No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblRegistrationNo" runat="server" Text="XYZ"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforVIN" runat="server" Text="VIN No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblVIN" runat="server" Text="XYZ"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforManufacturer" runat="server" Text="Manufacturer Name:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblManufacturer" runat="server" Text="123456"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforModel" runat="server" Text="Model Name:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblModel" runat="server" Text="123456"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforFuelType" runat="server" Text="Fuel Type:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblFuelType" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforEnginesize" runat="server" Text="Engine Size:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblEnginesize" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforEngineNo" runat="server" Text="Engine No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblEngineNo" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforcolor" runat="server" Text="Color:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblcolor" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforYearBuild" runat="server" Text="Year of build:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblYearBuild" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="panel-body">
                    <div class="heading">
                        <h4>Items Details</h4>
                    </div>
                    <table id="tblItems" class="nav-justified" border="1" style="border: thin inset #999999">
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 33%; background-color: red; color: white">Services</td>
                            <td style="width: 33%; background-color: red; color: white">Spare Parts</td>
                            <td style="width: 33%; background-color: red; color: white">Tachnician </td>
                        </tr>
                        <tr>
                            <td style="width: 33%">
                                <asp:GridView ID="gvServices" runat="server"></asp:GridView>
                            </td>
                            <td style="width: 33%">
                                <asp:GridView ID="gvSpare" runat="server"></asp:GridView>

                            </td>
                            <td style="width: 33%">
                                <asp:GridView ID="gvTech" runat="server"></asp:GridView>

                            </td>
                        </tr>
                    </table>
                </div>
                <div class="panel-body">
                    <div class="heading">
                        <h4>Office Use Only</h4>
                    </div>
                    <table class="nav-justified" border="1" style="border: thin inset #999999">
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 100%; background-color: red; color: white">Office Use</td>

                        </tr>
                        <tr style="text-align:justify; font-size: medium; color: #000000;">
                            <td style="width: 100%">
                                <div>
                                    uiuiht8d7yjgnjgixtixjtn
                                </div>
                            </td>
                        </tr>
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 100%">
                                <div style="text-align: left">
                                    Address :
                                    <asp:Label ID="lblOfficeAddress" runat="server" Text="office adress"></asp:Label>
                                </div>

                            </td>

                        </tr>
                    </table>

                </div>
                <div class="panel-body">
                    <p style="text-align: justify">I hereby authorize the above repair work to be done along with the necessary material, and hereby grant you and/or your empoyees permission to operate the car, truck or vechicle herein described on streets, highways or elsewhere for the purpose of testing and/or inspection. An express mechanic's lien is hereby acknowledged on above car, truck or vehicle to secure the amount of repair thereto.</p>
                    <div>

                        <table class="nav-justified" style="color: black; font-size: medium;">
                            <tr>
                                <td>Work Authorized By:____________________</td>
                                <td style="text-align: right">Date Promised:
                                    <asp:Label ID="lblDatePromised" runat="server" Text="x/xx/2222"></asp:Label></td>
                            </tr>
                            <tr>
                                <td>Delivered To:____________________</td>
                                <td style="text-align: right">Date Delivered:
                                    <asp:Label ID="lblDateDelivered" runat="server" Text="x/xx/2222"></asp:Label></td>
                            </tr>
                        </table>

                    </div>
                </div>
            </div>
        </div>
        <asp:LinkButton ID="LinkButton1"  runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
    </div>


</asp:Content>

I wants to print this page but when i use window.print(); it gives some different o/p it does not includes css effects as well header and footer which came from master are also not in formats... thank you....!!!!

expected o/p 在此处输入图片说明

getting 在此处输入图片说明

You have to define printing layout in css via "CSS Media queries"

eg

@media print {
    p { font-weight: bold; }
}

if you need custom layout when page is printed.

Or you can define a special css file for printing like this

<link rel="stylesheet" type="text/css" href="print.css" media="print">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM