Hi I’ve just set up a method in my website to send an email from a Contact Us page, I wanted to clear the asp.net form of all of the email details once they have sent the email so I’ve used a response.redirect to refresh the page as such. I want to display a message or a pop up window to show that the message has been sent, but because the page is being refreshed the label I am trying to write this to never gets called. Is there any way around this or a way to clear the form without a redirect? Here is the code I am working with:
protected void SubmitBtn_Click(object sender,EventArgs e)
{
MailMessage mailObj = new MailMessage(
EmailTxt.Text, "xxxxx@xxxxx.com", SubjectTxt.Text, MessageTxt.Text);
SmtpClient SMTPServer = new SmtpClient("localhost");
try
{
SMTPServer.Send(mailObj);
Response.Redirect("ContactMe.aspx");
base.OnLoad(e);
MessageLbl.Text = "Email Sent SucessFully.";
}
catch (Exception ex)
{
MessageLbl.Text = ex.ToString();
}
}
Many Thanks in advance
The
Response.Redirectis your problem. You are effectively refreshing the page and any code after that is irrelevant. Why not just clear the form via clode (i.e.myTextBox.Text = string.Emptyetc. and then set the message text?