提交时清除文本框

时间:2012-02-14 10:40:47

标签: c# asp.net

您好我希望在用户点击按钮时清除文本框。但是我的代码不起作用。这是我的代码。

System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
            m.Body = name.Text + Environment.NewLine + phone.Text + Environment.NewLine + email.Text + Environment.NewLine + message.Text;
            m.IsBodyHtml = false;
            m.To.Add("support@");
            m.From = new System.Net.Mail.MailAddress(email.Text);
            m.Subject = "Contact us form submisson";
            m.Headers.Add("Reply-To", "your email account");

            System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient();
            s.UseDefaultCredentials = false;
            s.Credentials = c;
            s.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            s.EnableSsl = true;
            s.Port = 587;
            s.Host = "smtp.gmail.com";

            s.Send(m);

            lblCorrectCode.Text = "Contact Form Has been submited we will be in touch shortly";

            name.Text = string.Empty;
            phone.Text = string.Empty;
            email.Text = string.Empty;
            message.Text = string.Empty;

1 个答案:

答案 0 :(得分:0)

我当然希望你不会在页面加载中填充它而不检查isPostBack

try
{
 s.Send(m);
}
finally
{

            lblCorrectCode.Text = "Contact Form Has been submited we will be in touch shortly";

            name.Text = string.Empty;
            phone.Text = string.Empty;
            email.Text = string.Empty;
            message.Text = string.Empty;
}