print different divs on buttone click in asp.net

Last post 07-10-2009 4:32 PM by bhavin shah. 3 replies.

Sort Posts:

  • print different divs on buttone click in asp.net

    07-05-2009, 7:59 AM
    • Member
      2 point Member
    • mahajan344
    • Member since 02-16-2009, 4:57 PM
    • Posts 14

    hello i wanna print a page..not the full page . i just wanna print some of it...
    please see the attachment...
    i just wanna print
     "Name",Admission No","Roll No",Toatl Amount,relaxation,Amount received....

    please give me solution in not in vb.net....
    thnx in advance...


    i have different divs in one page.. but i wanna display some of them, on one button clcik..




    Filed under: , ,
  • Re: print different divs on buttone click in asp.net

    07-05-2009, 8:21 AM

    try the below sample, and customize it as you want


    News ID : <asp:textbox id="txtId" runat="server" />
    <br/>
    News Title : <asp:textbox id="txtTitle" runat="server" />
    
    News Item : <asp:textbox id="txtItem" runat="server" />
    
    
    New Body : <div id="dvContent"> SomeText SomeText SomeText</div>
    
    
    <asp:button runat="server" Text="Preview Page" 
      OnClientClick="fnPrintPreveiw();return false;" />
    
    <script language="javascript" type="text/javascript">
         
       //===================================
       //Printer Freindly Version 
       
       
        function fnPrintPreveiw()
       {
       
    var newsId = document.getElementById('txtId').value
    var newsTitle = document.getElementById('txtTitle').value
    var newsItem = document.getElementById('txtItem').value
    var newBody = document.getElementById('dvContent').innerHTML;
    
        var disp_setting="toolbar=no,location=no,directories=no,menubar=no,";
        disp_setting+="scrollbars=no,left=0,top=0,resizable=yes,width=900, height=650,";
     
        var docprint=window.open("","",disp_setting);
        docprint.document.open();
        docprint.document.write('<html><head><title></title>');
      
        docprint.document.write('</head><body onload=""window.print();"">'); 
    docprint.document.write('News ID:');    
    docprint.document.write(newsId);      
    
    docprint.document.write('<br/>');  
    
    docprint.document.write('News Title:');    
    docprint.document.write(newsTitle);   
    
    docprint.document.write('<br/>');  
    
    docprint.document.write('News Item:');    
    docprint.document.write(newsItem);   
    
    docprint.document.write('<br/>');  
    
    
    docprint.document.write('News Body:');    
    docprint.document.write(newBody);   
    
    docprint.document.write('<br/>');  
    
    
              
        docprint.document.write("</body></html>"); 
        docprint.document.close(); 
        docprint.focus(); 
        
    }
    
    </script>



    Plz remember to click "Mark as Answer" if this helped you.

    Abdulla AbdelHaq    MCTS, MCPD

    - My Articles on ASP Alliance
    - My Weblogs
    - My Sessions on JorDev User Group

    "Experience is simply the name we give our mistakes"
  • Re: print different divs on buttone click in asp.net

    07-05-2009, 9:01 AM
    • Member
      2 point Member
    • mahajan344
    • Member since 02-16-2009, 4:57 PM
    • Posts 14

    not working dude ???



  • Re: print different divs on buttone click in asp.net

    07-10-2009, 4:32 PM
    • Participant
      1,381 point Participant
    • bhavin shah
    • Member since 07-02-2009, 4:34 PM
    • New York
    • Posts 241

    Hello,

    Create class noprint in style media print. and put noprint css class to what ever control you dont want to display while printing.

    <style>

    @media print{

    .noprint{display:none;}

    }

    </style>

    <div Class="noprint">

    this will not print

    </div>

    i hope this helps...

    IF YOU FEEL MY POST WAS THE RIGHT ANSWER PLEASE MARK IT AS ANSWER.........

    http://www.linkedin.com/in/bhavinjshah
Page 1 of 1 (4 items)