我的代码如下所示。我的按钮点击事件有点问题。当我运行visual studio调试时,它在我的localhost上正常工作,但是当我在服务器上传文件时,这个按钮点击事件无效。 下面是我的.aspx页面
<div class="apply-job" style="padding-top:10px">
<div class="container">
<div class="row">
<div class="col-md-8 ap-form-sec" style="float:left">
<h3 class="font-title">Contact <span>Us</span></h3>
<div class="row">
<div class="col-md-12">
<form class="apply-job-form">
<div class="row">
<div class="col-md-6">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
<asp:TextBox ID="txtfirstname" runat="server" CssClass="form-control" placeholder="First Name"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<asp:TextBox ID="txtsub" runat="server" CssClass="form-control" placeholder="Subject"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<asp:TextBox ID="txtadd" runat="server" CssClass="form-control" placeholder="Home Address"></asp:TextBox>
</div>
<div class="col-md-6">
<asp:TextBox ID="txtstate" runat="server" CssClass="form-control" placeholder="State"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<asp:TextBox ID="txtphone" runat="server" CssClass="form-control" placeholder="Phone"></asp:TextBox>
</div>
<div class="col-md-6">
<asp:TextBox ID="txtemail" runat="server" CssClass="form-control" placeholder="Email"></asp:TextBox>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
<asp:TextBox ID="txtlastname" runat="server" CssClass="form-control" placeholder="Last Name"></asp:TextBox>
</div>
</div>
<div class="form-group" style="margin-bottom:6px">
<div class="col-md-12">
<asp:TextBox ID="txtmsg" runat="server" CssClass="form-control" placeholder="Message" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<asp:TextBox ID="txtcity" runat="server" CssClass="form-control" placeholder="City"></asp:TextBox>
</div>
<div class="col-md-6">
<asp:TextBox ID="txtzip" runat="server" CssClass="form-control" placeholder="Zip code"></asp:TextBox>
</div>
</div>
</div>
</div>
<div class="text-content center">
<div class="col-md-12">
<asp:Button ID="Button1" runat="server" Text="Submit Your Application" CssClass="btn btn-default" OnClick="Button1_Click"/>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
下面是我的.aspx.cs页面。我使用System.net.mail命名空间发送邮件。我认为问题是当我点击按钮时它没有触发按钮的点击事件和做其余的事情或者我认为可能是一些css冲突。
protected void Page_Load(object sender, EventArgs e)
{
}
protected void clearcontrol()
{
txtfirstname.Text = "";
txtlastname.Text = "";
txtcity.Text = "";
txtstate.Text = "";
txtemail.Text = "";
txtphone.Text = "";
txtsub.Text = "";
txtadd.Text = "";
txtmsg.Text = "";
txtzip.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
System.Net.Mail.MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient()
{
Host = "smtp.gmail.com",
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network,
//UseDefaultCredentials = true,
Credentials = new NetworkCredential("shreehe741@gmail.com", "**********"),
EnableSsl = true
};
MailAddress esender = new MailAddress("shreehe741@gmail.com");
mail.From = esender;
MailAddress erec = new MailAddress("shreehe741@gmail.com");
mail.To.Add(erec);
mail.IsBodyHtml = true;
mail.Body = "<html> " +
"<head> " +
"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> " +
"<title> Appointment </title> " +
"</head> " +
"<body> " +
"<table width='400px' border='0' cellspacing='0' cellpadding='2' > " +
"<tr> " +
"<td><h4>Applicant name is</h4> " + txtfirstname.Text +" "+txtlastname.Text+ "</td> " +
"</tr>" +
"<tr> " +
"<td><h4>Subject of application is</h4>" + txtsub.Text + "</td> " +
"</tr>" +
"<tr> " +
"<td><h4>Address of applicant name is</h4> " + txtadd.Text + " ," + txtcity.Text+","+txtstate.Text +","+txtzip.Text+ "</td> " +
"</tr>" +
"<tr>" +
"<td><h4>Contact details are given as below </h4> </td> " +
"</tr>" +
"<tr>" +
"<td><h5>Phone number is</h5> " + txtphone.Text + "</td> " +
"<td><h5>Email id is</h5> " + txtemail.Text + "</td> " +
"</tr>" +
"<tr>" +
"<td><h4>Message from user </h4>" + txtmsg.Text + "</td> " +
"</tr>" +
" </table> " +
" </body> " +
" </html>";
mail.Subject = "Appointment";
smtp.Send(mail);
Response.Write("<script>alert('Your appiontment saved')</script>");
clearcontrol();
}
catch (Exception ex)
{
Response.Write("<script>alert('Error :" + ex.Message + "');</script>");
}
}
我在过去的4天里一直在与这个问题作斗争,但我仍然无法找到我失踪的东西。即使我点击后也没有收到任何异常消息服务器上的按钮..