Click here to Skip to main content
15,909,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web form that has different controls on it. I want to use a panel control for when a user clicks print the controls in the panel will be printed. How can i add more panels to print within my code? Can the panel control also print tables?

The first code is the HTML Markup:

ASP.NET
<%@ Page Language="C#" AutoEventWireup="True" Inherits="FinancialProfileFormA" Codebehind="FinancialProfileFormA.aspx.cs" %>

<!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></title>
    <style type="text/css">
        .style1
        {
            font-size: x-large;
            text-align: center;
        }
        .style2
        {
            width: 100%;
        }
        .style5
        {
            width: 20px;
        }
        .style7
        {
            width: 495px;
            font-weight: bold;
        }
        .style9
        {
            width: 20px;
            height: 23px;
        }
        .style10
        {
            width: 495px;
            height: 23px;
            font-weight: bold;
        }
        .style11
        {
            height: 23px;
        }
        .style18
        {
            font-weight: bold;
        }
        .style19
        {
            width: 905px;
            text-align: center;
        }
        .style21
        {
            width: 212px;
            font-weight: bold;
        }
        .style22
        {
            width: 212px;
            height: 23px;
            font-weight: bold;
        }
        .style23
        {
            font-size: small;
        }
        .style24
        {
            font-size: small;
            font-weight: normal;
        }
        .newStyle1
        {
        }
        .style3
        {
            width: 100%;
        }
        .style35
        {
            width: 469px;
            font-weight: bold;
            font-size: large;
        }
        .style36
        {
            width: 469px;
        }
        .style37
        {
            font-size: large;
            width: 439px;
        }
        .style38
        {
            font-size: x-large;
            width: 200px;
        }
        .style40
        {
            width: 645px;
            height: 23px;
            text-align: right;
        }
        .style41
        {
            width: 645px;
            height: 23px;
            font-weight: bold;
            text-align: right;
        }
        .style42
        {
            height: 23px;
            width: 190px;
        }
        .style47
        {
            font-size: large;
            text-align: center;
        }
        .style48
        {
            font-size: xx-large;
        }
        .style49
        {
            font-size: x-large;
        }
        .style50
        {
            width: 585px;
            height: 137px;
        }
        .style51
        {
            font-weight: bold;
            font-size: x-large;
            text-align: center;
        }
        .style52
        {
            width: 670px;
        }
        .style53
        {
            width: 495px;
        }
        .style54
        {
            width: 212px;
        }
        .style55
        {
            font-size: x-large;
            width: 212px;
            text-align: center;
        }
        .style56
        {
            font-weight: bold;
            font-size: large;
            text-align: center;
        }
        .style57
        {
            width: 200px;
        }
    </style>
    <script language="javascript" type="text/javascript">
// <![CDATA[

        function Reset1_onclick() {

        }

// 
    </script>
</head>
<body background="Images/bkg-blu.jpg" bgcolor="#3399ff">
    <form id="form1"  runat="server">
    <div class="style1">
    
        <div style="text-align: left">
                                                                                                                     <table 
                class="style2">
                <tr>
                    <td style="text-align: center">
                        <img class="style50" src="Images/buildout_header.jpg" /></td>
                </tr>
            </table>
                                                                           
                                                                                                                                      
                                                                    
        </div>
    
        
        <span class="style48">
        <br />
        Financial Profile </span></div>
    <br />
                
    <asp:TextBox ID="TextBoxaccessLevel" runat="server" style="text-align: center" 
        Visible="False"></asp:TextBox>
                
    <br />
    <asp:TextBox ID="TextBoxINST_ID" runat="server" Enabled="False" ReadOnly="True" 
        Visible="False"></asp:TextBox>
    <br />
    <table class="style2">
        <tr>
            <td style="text-align: center">
                <asp:Label ID="lblSchool" runat="server" CssClass="style51"></asp:Label>
            </td>
        </tr>
    </table>
    <table class="style2">
        <tr>
            <td class="style52" style="text-align: right">
                <asp:Label ID="lblCity" runat="server" CssClass="style56"></asp:Label>
                ,</td>
            <td>
 <asp:Label ID="lblState" runat="server" CssClass="style56"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style52" style="text-align: right">
                 </td>
            <td style="text-align: right">
                <asp:Label ID="lblDate" runat="server" style="font-weight: 700" 
                    Text="Today's Date"></asp:Label>
 
                <asp:TextBox ID="TextBoxDATE" runat="server" 
                    style="font-weight: 700; text-align: center" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style52" style="text-align: right">
                 </td>
            <td style="text-align: right">
                <asp:Label ID="lblTime" runat="server" style="font-weight: 700"></asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style5">
                 </td>
            <td class="style53">
                 </td>
            <td class="style55">
                <asp:Label ID="lblLYEAR" runat="server" style="font-weight: 700"></asp:Label>
            </td>
            <td>
                <span class="style49">           
                <asp:Label ID="lblYEAR" runat="server" style="text-align: center">2013</asp:Label>
                </span></td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style53">
                </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style3">
        <tr>
            <td class="style37">
                 </td>
            <td class="style38">
                ^__strong__^     <asp:Label ID="lblLYEAR2" runat="server"></asp:Label>
                </strong__^</td>
            <td class="style35">
                ^__strong style="font-size: x-large"__^           
                <asp:Label ID="lblYEAR2" runat="server">2013</asp:Label>
                </td>
        </tr>
        <tr>
            <td class="style37">
                 </td>
            <td class="style57">
                 </td>
            <td class="style36">
                 </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator30" runat="server" 
                    ControlToValidate="TextBoxTA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Liabilities</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTL" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTL" runat="server" Width="180px" AutoPostBack="True" 
                    ontextchanged="TextBoxTL_TextChanged">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator31" runat="server" 
                    ControlToValidate="TextBoxTL" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__strong__^Total Net Assets</td>
            <td class="style57">
                 </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Nonexpendable/Permanently Restricted Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYNPRNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxNPRNA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator32" runat="server" 
                    ControlToValidate="TextBoxNPRNA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Expendable/Temporarily Restricted Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYETRNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxETRNA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator33" runat="server" 
                    ControlToValidate="TextBoxETRNA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Unrestricted Net Assets <span class="style23">(Unrestricted net assets 
                Plus capital assets, net)</span></td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTUNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTUNA" runat="server" Width="180px" AutoPostBack="True" 
                    ontextchanged="TextBoxTUNA_TextChanged">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator34" runat="server" 
                    ControlToValidate="TextBoxTUNA" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Revenue</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTR" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTR" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator35" runat="server" 
                    ControlToValidate="TextBoxTR" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Tuition and Fees, Net</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTFN" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTFN" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator36" runat="server" 
                    ControlToValidate="TextBoxTFN" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Current Debt</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYCD" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxCD" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator37" runat="server" 
                    ControlToValidate="TextBoxCD" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Long-term Debt</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYLTD" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxLTD" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator38" runat="server" 
                    ControlToValidate="TextBoxLTD" 
                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                ^__b__^Total Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTNA" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTNA2" runat="server" Width="180px" Enabled="False" 
                    ReadOnly="True"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator1" runat="server" 
                    ControlToCompare="TextBoxTNA" ControlToValidate="TextBoxTNA2" 
                    ErrorMessage="The Entry Does Not Match Each Other!!" ForeColor="Red"></asp:CompareValidator>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style3">
        <tr>
            <td class="style40">
                ^__strong__^Name</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxFullN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                    ControlToValidate="TextBoxFullN" ErrorMessage="Please Give Your Full Name!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong__^Title</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxTitle" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                    ControlToValidate="TextBoxTitle" ErrorMessage="Please Give Your Title!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong__^Institution</td>
            <td class="style42">
                <asp:Label ID="lblSchool2" runat="server"></asp:Label>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong__^Mailing ^__strong>Address</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxMA" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                    ControlToValidate="TextBoxMA" 
                    ErrorMessage="Please Give Your Mailing Address!!!" ForeColor="Red" 
                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style41">
                 </td>
            <td class="style42">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong>Telephone Number</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxTN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
                    ControlToValidate="TextBoxTN" 
                    ErrorMessage="Please Give Your Telephone Number!!!" ForeColor="Red" 
                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong>Fax Number</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxFN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" 
                    ControlToValidate="TextBoxFN" ErrorMessage="Please Give Your  Fax Number!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                ^__strong>Email Address</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxEA" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" 
                    ControlToValidate="TextBoxEA" ErrorMessage="Please Give Your Email Address!!!" 
                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style19">
                                                                
                <asp:Button ID="ButtonSubmit" runat="server" onclick="ButtonSubmit_Click" 
                    Text="Submit" Width="100px" style="text-align: center" />
            </td>
            <td>
                <asp:Button ID="ButtonPrint" runat="server" Text="Print" Width="100px" />
            </td>
        </tr>
    </table>
    </form>
    </body>
</html>


The next code is the print button code:

C#
protected void ButtonPrint_Click(object sender, EventArgs e)
        {
            Session["ctrl"] = Panel1;
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=300px,width=300px,scrollbars=1');</script>");
        }

What I am saying is that if I have more than one Panel control How would I add that to my code?
Posted
Comments
JoCodes 14-Jan-14 9:01am    
Where is the panel here? Cant see any panel control in your markup.Can you explain what you are looking for?
Computer Wiz99 14-Jan-14 9:28am    
Ok, If you take the print code that I have for the print button, How can I include other Panel controls within that print code? Will I just put in Panel1;, Panel2;, Panel3; and so on or will the code be different?
JoCodes 14-Jan-14 9:31am    
Right now you are just printing the page using the window.open js method. You mean to say you need to pass panel to that client side print code so that only that panels will be printed?Correct me if I understood differently
Computer Wiz99 14-Jan-14 9:39am    
Yes. As I have different panels to print. Is there a way to print a panel and not include some controls? I have a table that as two sets of textboxes. I would not need the textboxes with the Textbox ID starting with LY. Is there a way to cancel those textboxes when a user prints?

1 solution

Contents of the Panel control can be selectively printed . In case , need to exclude some controls , easiest way is to do it using CSS .

Adding references which will give you an idea

http://forums.asp.net/t/1706754.aspx[^]

http://www.dotnetcurry.com/showarticle.aspx?ID=92[^]

More reference on Print Style sheets

http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml[^]
 
Share this answer
 
v2
Comments
Computer Wiz99 14-Jan-14 10:08am    
JoCodes, Thanks for the links. Where should /* Remove unwanted elements */
#header, #nav, .noprint
{
display: none;
}
be in the HTML markup?
JoCodes 14-Jan-14 10:22am    
yes

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