我有一个按钮应该发送一个电子邮件的aspx页面...我的代码似乎设置正确,但是当按钮被点击时,什么也没有发生。这是代码。它的目的是显示一个警报,然后重定向到成功页面,但没有任何反应...ASPX按钮 - 没有任何反应
没有onclick,但根据这个,不应该有:http://www.velocityreviews.com/forums/t367616-using-handles-vb-vs-c.html也是指南我从这个代码没有'也可以使用onclick,尽管它已经过时了。
标记是:
<%@ Page Title="Sign Up" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="signup.aspx.cs" Inherits="WebApplication2._Default" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Email Service
</h2>
Re-enter your email address to confirm signup for updates.
<br />
<table border="0">
<tr>
<td><b>Email:</b></td>
<td><asp:TextBox runat="server" ID="UsersEmail" Columns="30"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button runat="server" ID="SendEmail" Text="Sign Up"/>
</td>
</tr>
</table>
代码隐藏是:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SendEmail_Click(object sender, EventArgs e) //Handles SendEmail.Click
{
try
{
//!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
string ToAddress = "[email protected]";
//(1) Create the MailMessage instance
MailMessage mm = new MailMessage(UsersEmail.Text, ToAddress);
//(2) Assign the MailMessage's properties
mm.Subject = UsersEmail.Text + " would like to sign up for updates";
mm.Body = "Hello, I would like to sign up for updates. My email is " + UsersEmail.Text + ". Thank you.";
mm.IsBodyHtml = false;
//(3) Create the SmtpClient object
SmtpClient smtp = new SmtpClient("[removed]");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm);
}
catch (Exception ex)
{
string strError = "<Script language=javascript>alert('Error');</Script>";
Response.Write(strError);
Response.Redirect("Success.aspx");
}
string strMsg = "<Script language=javascript>alert('Emailsent');</Script>";
Response.Write(strMsg);
Response.Redirect("Success.aspx");
//System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Hello this is an Alert"")</SCRIPT>");
}
}
}
我真怀疑的onclick是解决方案,无论如何,因为无法处理任何代码..
任何想法?谢谢。
使用的onclick尝试的 –
2012-03-28 18:10:18
什么是您的aspx.cs文件的名称?它是“signup.aspx.cs”还是“_Default.aspx.cs”? – daniloquio 2012-03-28 18:13:33
我想知道不需要为自定义输入操作连接事件处理程序的印象来自哪里? – 2012-03-28 18:56:34