简体   繁体   中英

message box show in asp.net problem

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM