我有一个 asp.net 3.5 网络表单,我正在使用多个服务器端验证器控件,我希望在验证页面后,在提交按钮单击事件处理程序时触发打印的 javascript 代码
我尝试使用 OnClientClick 但这甚至会在页面无效时触发打印页面 javascript,
我将如何做到这一点,打印仅在表单有效时显示?
这是我的代码,提前谢谢
<asp:Button ID="btnAction" runat="server" OnClick="btnAction_Click"
Text="Submit" />
protected void btnAction_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
// define SMTP client
SmtpClient smtp = new SmtpClient();
//create the mail message
MailMessage message = new MailMessage();
//From address will be given as a MailAddress Object
//To address collection of MailAddress
message.To.Add("########");
//CC and BCC optional
//message.CC.Add("");
// Change to false to not include HTML
message.IsBodyHtml = true;
message.Body += "<h2>info goes here</h2></br></br>";
//send the message
try
{
smtp.Send(message);
}
catch (System.Net.Mail.SmtpException ex)
{
throw new Exception(ex.Message.ToString());
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
Page.ClientScript.RegisterStartupScript(this.GetType(),
"OnPrintPage", "window.print();", true);
Response.Redirect("Confirmation.aspx?value=" +
Server.UrlEncode(confirmationNumber));
//Passing in session
//Session["sessionname"] = confirmationNumber;
}
//End if Page is Valid Block
}