c# - how to print the content of a label or panel in asp.net? - Stack Overflow

I have a label control in a page in asp 2.0 and a button Print.Clicking on print button I need to print

I have a label control in a page in asp 2.0 and a button Print.

Clicking on print button I need to print the content of the label and I need same for a panel also.

Is it possible to implement this?

If yes then how to implement that?

Please help.

I have a label control in a page in asp 2.0 and a button Print.

Clicking on print button I need to print the content of the label and I need same for a panel also.

Is it possible to implement this?

If yes then how to implement that?

Please help.

Share Improve this question asked Jan 4, 2010 at 7:26 HimadriHimadri 8,87616 gold badges49 silver badges70 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 1

What about Window.Print() method? Because execmand method will not work other browsers that IE. Use CSS media option to control the print area.

You would need to add some client side javascript to your Print button to execute the brower's print mand. The javascript below could be used to print the whole document page and would be a good place to start. Note: It isn't possible to do this without displaying the print dialog unless you use a third party ponent.

// Print Page   
window.print();

If you wanted just to print certain sections of your page you can achieve this two ways. Firstly, you could render the content to be printed into a hidden iframe and then print just that frame. You would do this using the same code as above only from within the frame itself.

Secondly, you could use a media style print style sheet, a CSS that applies only when printing. Inside this sheet you would set the styles you wanted to print as normal and the styles you didn't want to print to "display:none". The link below contains more information on print stylesheets.

http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml

One more approach could be to open new window and populate the contents of div you wanted to print and have print link/button on that page. Ex:

var win = window.open(...) win.document.body.appendChild(document.getElementById('divToPrintId'))

This is how the code will look like this approach is used to print the content/part of the page.

Use below code in button onclick event

ClientScript.RegisterStartupScript(this.GetType(), "PrintOperation", "PrintGridData()", true);

Above link will call function named PrintGridData() which is written in head section as below

<script type="text/javascript">
    function PrintGridData() 
    {
        var prtGrid = document.getElementById('<%=GridView.ClientID %>');
        prtGrid.border = 0;
        var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1, status=0,resizable=1');
        prtwin.document.write(prtGrid.outerHTML);
        prtwin.document.close();
        prtwin.focus();
        prtwin.print();
        prtwin.close();
    }
</script>

in this script it will only print div name GridView and other part will not be printed

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745103958a4611447.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信