如何保持当前屏幕而不去顶部(看起来像刷新)

时间:2017-10-20 16:49:21

标签: c# asp.net system.net.mail

我使用了System.Net.Mail。我有两个问题。

首先,在我提交之后,lblMessage.Text正在显示,页面将显示在顶部。所以我想要的是当我提交时,页面保留在我的提交按钮中。

其次,我提交后,数据仍然存在,如果刷新页面,它将再次重新提交。

如何弄清楚这两个问题。感谢。

   public partial class Contact : Page
    {
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("xxx@gmail.com");
                msg.To.Add("xxx@hotmail.com");
                msg.Subject = txtSubject.Text;
                msg.Body = "<h1>" + txtName.Text + " <br />" + "<h3> Phone Number: " + txtPhone.Text + "<br />" + "Email Address: " + txtEmail.Text + "<br />" + "Message: <br />" + txtMessage.Text + ".<br />";
                msg.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                /*
                Sl.No   Mail Server SMTP Server( Host ) Port Number
                1   Gmail   smtp.gmail.com  587
                2   Outlook smtp.live.com   587
                3   Yahoo Mail  smtp.mail.yahoo.com 465
                4   Yahoo Mail Plus plus.smtp.mail.yahoo.com    465
                5   Hotmail smtp.live.com   465
                6   Office365.com   smtp.office365.com  587
                7   zoho Mail   smtp.zoho.com   465
               */
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName = "xxxxx@gmail.com";
                NetworkCred.Password = "BLACKroseFh521";
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.Send(msg);
                lblMessage.Text = "Email has been successfully sent! <br />We will be in touch soon.";
            }

        }
    }

0 个答案:

没有答案