如何将代码写入一个按钮,该按钮必须同时触发onclick和onclientclick两个事件同时单击 [英] How do I write code to a button which must fire on both events onclick and onclientclick simultaneously with single click

查看:97
本文介绍了如何将代码写入一个按钮,该按钮必须同时触发onclick和onclientclick两个事件同时单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用js编写按钮onclient事件的代码来打印网页和onclick事件以生成pdf并下载它..两个必须在一个动作中完成..

但是当我取消打印时我onclient click事件然后oncick事件正在解雇。



我尝试过:



iam writing code for button onclient event with js to print the webpage and onclick event for generating pdf and downloading it ..both must be done in a single action..
but when i cancel print which i onclient click event then oncick event is firing .

What I have tried:

 <script type="text/javascript">
         function PrintPage() 
         {
             window.print();
            return true;
         }
</script>




<asp:Button ID="Button3" runat="server"  Text="PTPDF" UseSubmitBehavior="false" OnClick="Button3_Click1"  OnClientClick ="javascript:PrintPage();"    />
       </div>







protected void Button3_Click1(object sender, EventArgs e)
        {//here is the code for pdf generation,
this code must get fired automatically after onclient click event without users action}

推荐答案

OnClientClick 事件将首先被触发,它将接受布尔值(默认为true)

如果值为true, onclick 事件将被触发,否则它不会。

它应该是
OnClientClick event will be fired first, it will accept boolean value ( true by default )
if the value is true, onclick event will be fired, else it wont.
it should be
OnClientClick =" return PrintPage();" 



然而 window.print()方法不会返回任何值,所以很难知道是否单击打印或取消按钮。

检查这一点,它可能对您有帮助如何在Javascript window.print()调用的默认打印菜单上捕获click事件? - 堆栈溢出 [ ^ ]


however the window.print() method will not return any value, so its difficult to know that whether the print or cancel button is clicked.
check this, it might help you How to capture the click event on the default print menu called by Javascript window.print()? - Stack Overflow[^]


这篇关于如何将代码写入一个按钮,该按钮必须同时触发onclick和onclientclick两个事件同时单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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