2012-02-14 65 views
0

您好,我希望在用戶單擊按鈕時清除文本框。然而,我有的代碼不工作。這是我的代碼。提交時顯示文本框

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("[email protected]"); 
      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; 
+0

您是否收到錯誤消息? – 2012-02-14 10:42:51

+0

沒有它只是不工作,當我點擊提交它不會清除文本框 – Inkey 2012-02-14 10:44:00

+2

@Madhav你是認真的嗎? – 2012-02-14 10:56:26

回答

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; 
}