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)
链接地址: http://www.djcxy.com/p/71532.html

上一篇: asp.net:确认后重定向到页面?

下一篇: 消息框显示在asp.net问题