如何将代码写入一个按钮,该按钮必须同时单击同时对两个事件发射onclick和onclientClick



iam编写js的按钮onclient事件的代码,以打印网页和onclick事件,以生成pdf并下载它。但是,当我取消我onclient单击事件的打印时,oncick事件正在触发。

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

<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,

此代码必须在无用户操作的情况下单击事件后自动发射}

code下方在我的末端完美工作,而 illustrates OnClickOnClientClick在同一时间工作方式 -

aspx-

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Click.aspx.cs" Inherits="Click" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
function confirmthis()
{
    document.getElementById('TextBox2').value = 'onclient works';    
}
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="return confirmthis();" Text="Click Me" /></div>
    </div>
    </form>
</body>
</html>

内联代码 -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Click : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
   protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "OnClick works";
    }
}

paste在您结尾处上述code,让我知道它是否仍然不起作用。

谢谢!

最新更新