【发布时间】:2012-04-12 09:09:29
【问题描述】:
我在一个应该发送电子邮件的 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 = "info@removed.org";
//(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
-
您的 aspx.cs 文件的名称是什么?是“signup.aspx.cs”还是“_Default.aspx.cs”?
-
我想知道不需要为自定义输入操作连接事件处理程序的印象来自哪里?
标签: c# asp.net html email button