Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a form in which i get all employee security cards on by clicking a button,and another button to print these cards using jquery ,i have following code
ASP.NET
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <script type='text/javascript'>            
            $(function () {                
                $("#spcards").find('.print').on('click', function () {
                    $.print("#spcards");
                });                
            });            
	</script>  
             <div class="col-sm-2">
                     <asp:Button ID="EmpSC" CssClass ="btn btn-green btn-block " Width="150" runat="server" OnClick="EmpSC_Click" Text="Create Sc" />
                </div>
        <br />
         <button class="print"> Print this </button>
        <div id="spcards"  runat="server">
          
        </div>

and c# code is
C#
protected void EmpSC_Click(object sender, EventArgs e)
       {
           EmployeeSpDataSet dataset = new EmployeeSpDataSet();
           StringBuilder sb = new StringBuilder();
           var AllEmp = _service.GetAllEmployeeDuty().OrderByDescending(x => x.EndDate).GroupBy(x => x.Employee_Id).Select(x => x.First()).Take(3).ToList();
           if (AllEmp != null)
           {
               for (int i = 1; i <= 3; i++)
               {
                   var empsp = AllEmp.FirstOrDefault();
                   var emp = _service.GetAllEmployee().Where(x => x.Id == empsp.Employee_Id).FirstOrDefault();
                   dataset.EmployeeScpass.Rows.Add(emp.Id,
                       emp.Name,
                       emp.Cnic,
                       empsp.ToSectorName,
                       emp.ImgBody, ""
                       );

                   sb.Append("<table style=\"height:324px; width:504px; background-image:removed(../Images/PassFront.jpg)\">");
                   sb.Append("<tr style='height:200px;'>");
                   sb.AppendFormat("<td><img src=\"EmpPicture.ashx?id={0}\" style=\"height:200px; width:200px; margin-top:82px; margin-left:17px;\" /></td>", emp.Id);
                   sb.Append("<td><table>");
                   sb.AppendFormat("<tr><td>Name: </td><td>{0}</td></tr>", emp.Name);
                   sb.Append("</table></td></tr><tr><td></td><td></td></tr></table><br/>");

                   AllEmp.Remove(empsp);
               }
spcards.InnerHtml = sb.ToString();

              // sb.Append("<button class=\"print\"> Print this </button><br/>");
           }

how do i can do this
Posted
Updated 2-Jun-15 19:41pm
v2
Comments
What is the issue here? Is there any errors listed on console of Browser Developer Tool?
Sajid227 4-Jun-15 1:07am    
When I click on the button print button does not show any dialogue box for printing

1 solution

If you want to print all page use
window.print()

or if you want to print particular part of page then use below code.
JavaScript
$("#spcards").print();
 
Share this answer
 

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