admin管理员组文章数量:1025218
I have a USER CONTROL with a <div>
tag and a button. I want to print the content of the <div>
when the button is clicked. Only the content of the div
and nothing else no matter where the control is used. This without opening a new window. I cannot find a solution that works with every browser!
Thank you!
I have a USER CONTROL with a <div>
tag and a button. I want to print the content of the <div>
when the button is clicked. Only the content of the div
and nothing else no matter where the control is used. This without opening a new window. I cannot find a solution that works with every browser!
Thank you!
Share Improve this question asked Feb 2, 2010 at 14:35 UinceUince 1933 gold badges5 silver badges11 bronze badges 1- When you say print the content of the div, you mean you want to make like a printer-friendly page with only the contents of the div? – wsanville Commented Feb 2, 2010 at 14:39
3 Answers
Reset to default 4You might be able to generate a CSS file that excludes everything except the <div>
, something in the lines of:
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
And the putting something like this in print.css:
* { display: none; }
#specialdiv { display: block; }
In the server-side click handler of the button, send out the content you want to display:
protected void MyButton_Click(object sender, EventArgs e) {
Response.Clear();
Response.Write(...the content of your div; be nice and add at least some html headers...);
Response.End();
}
Clear
removes everything from the output buffer, Write
outputs your stuff and End
stops processing the rest of your page.
As kb said, use css to define what is and what isn't printed on a page. If you want a print button which prints just a div follow kb's instructions. If you still want file->print to behave as normal however, change the page's (media="print") css prior to calling window.print() and revert it afterwards in the button's onclick function.
Sorry to be the bearer of bad news but there isn't a prehensive print api for javascript!
I have a USER CONTROL with a <div>
tag and a button. I want to print the content of the <div>
when the button is clicked. Only the content of the div
and nothing else no matter where the control is used. This without opening a new window. I cannot find a solution that works with every browser!
Thank you!
I have a USER CONTROL with a <div>
tag and a button. I want to print the content of the <div>
when the button is clicked. Only the content of the div
and nothing else no matter where the control is used. This without opening a new window. I cannot find a solution that works with every browser!
Thank you!
Share Improve this question asked Feb 2, 2010 at 14:35 UinceUince 1933 gold badges5 silver badges11 bronze badges 1- When you say print the content of the div, you mean you want to make like a printer-friendly page with only the contents of the div? – wsanville Commented Feb 2, 2010 at 14:39
3 Answers
Reset to default 4You might be able to generate a CSS file that excludes everything except the <div>
, something in the lines of:
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
And the putting something like this in print.css:
* { display: none; }
#specialdiv { display: block; }
In the server-side click handler of the button, send out the content you want to display:
protected void MyButton_Click(object sender, EventArgs e) {
Response.Clear();
Response.Write(...the content of your div; be nice and add at least some html headers...);
Response.End();
}
Clear
removes everything from the output buffer, Write
outputs your stuff and End
stops processing the rest of your page.
As kb said, use css to define what is and what isn't printed on a page. If you want a print button which prints just a div follow kb's instructions. If you still want file->print to behave as normal however, change the page's (media="print") css prior to calling window.print() and revert it afterwards in the button's onclick function.
Sorry to be the bearer of bad news but there isn't a prehensive print api for javascript!
本文标签: aspnetprint div content from user control without opening a new windowStack Overflow
版权声明:本文标题:asp.net - print div content from user control without opening a new window - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745611548a2159030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论