打印Web表单时出现javascript错误 [英] javascript error while printing a web form

查看:84
本文介绍了打印Web表单时出现javascript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们!我在标记"中编写了以下代码,单击"btnPrint"按钮时出现错误..

错误:
"Microsoft JScript运行时错误:无法获取属性" style"的值:对象为null或未定义"

javascript:

Hi friends! I''ve written the following code in Markup, where I''m getting error when "btnPrint" button is clicked..

Error:
"Microsoft JScript runtime error: Unable to get value of the property ''style'': object is null or undefined"

javascript:

function PrintReport() {
    window.print();
    document.getElementById('btnPrint').style.visibility = 'hidden';
}



在表格行中:



in table row:

<asp:Button ID="btnPrint" runat="server" Text="Print"  OnClientClick="PrintReport()"/>



任何人都可以回答解决方案..

问候,
Ravi kamesh



Can anyone answer the solution plz..

Regards,
Ravi kamesh

推荐答案

这是因为您的html中没有ID为"btnPrint"的元素.
即使在服务器控件(按钮)中写id ="btnPrint",也不会在呈现页面时以相同的id结尾.

当心您的javascript中的订单

That is because there is no element with id ''btnPrint'' in your html.
Even if you write id="btnPrint" in your server control (button) it wont end up with that same id when the page is rendered.

be ware of the order in your javascript

function PrintReport() {
    var btnId = '<%=btnPrint.ClientID %>'; // find the server generated clientId

    // Hide before you call window.print()
    document.getElementById(btnId).style.visibility = 'hidden';

    window.print();
}


<style type="text/css" media="screen">
        .button
        {
            display: block;
        }
</style>
<style type="text/css" media="print">
        .button
        {
            display: none;
        }
</style>


和您的按钮代码


and ur button code

<asp:button id="btnPrint" runat="server" text="Print" onclientclick="javascript:window.print();" CssClass="button" />


这篇关于打印Web表单时出现javascript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆