0

I have an email compose page. When the user clicks on the "Send" button, if there is any error, the page is redirected to an error page. If the email is sent out successfully, it displays a javascript alert message. The way it's done now is using a label control, LblMessage.Text="alert('Your email has been sent successfully!');"; All of this works fine. Now I want to redirect the user to the home page. So if the email is sent out successfully, I want to display the javascript alert message, then do a redirect to home page. But if I add the response.redirect after the alert code, the alert never shows up. I tried changing the endReponse to true and false, it did not work. Any suggestions?

1 Answer 1

2

try to redirect your page with javascript. This redirection will be executed right after OK click:

LblMessage.Text="alert('Your email has been sent successfully!'); window.location = 'www.mypage.com/Default.aspx';";

And also it's a good practice to add scripts using ClientScriptManager.RegisterStartupScript like this:

ClientScriptManager.RegisterStartupScript(typeof(Page), "successfull", "alert('Your email has been sent successfully!'); window.location = 'www.mypage.com/Default.aspx';", true)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.