[英]I call a javascript function for print but doesn't work
I use below code for print from Page but doesn't work (means when i click on print button nothing happen). 我使用下面的代码从页面打印但不起作用(意味着当我点击打印按钮时没有任何反应)。 the function doesn't call
该功能不会调用
<script type="text/javascript">
function printing() {
window.print();
}
</script>
protected void print_Click(object sender, EventArgs e)
{
btnPrint.Attributes.Add("onclick", "return printing()");
}
试试这种方式:
<asp:Button ID="print" runat="server" Text="Print" OnClientClick="javascript:window.print();" />
Add attribute
in page_load event to bind
the javascript event
, so that the javascript is binded before you click the print button to print the page. 在page_load事件中添加
attribute
以bind
javascript event
,以便在单击打印按钮以打印页面之前bind
javascript。
private void Page_Load(object sender, System.EventArgs e)
{
btnPrint.Attributes.Add("onclick", "return printing()");
//Your code here.
}
When a user clicks the button, you are adding an attribute, not calling the printing()
function. 当用户单击该按钮时,您将添加一个属性,而不是调用
printing()
函数。
You should add the OnClientClick
attribute to the button in the button html like this: 您应该将
OnClientClick
属性添加到按钮html中的按钮,如下所示:
<asp:button OnClientClick="return printing" ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.