-1

Below is part of my codes in C#, it suppose to send email, show the msg box, then direct to 'Multihotelbook.aspx' page, but the direct to the page without showing the msgbox. i dont know why. need help

emailClient.Send(message);

                // Response.Write("<script>window.alert('Email sent')</script>");
                //ClientScript.RegisterStartupScript(typeof(Page), "myscript", "<script>alert('Email sent');</script>");
                // System.Windows.Forms.MessageBox.Show("Email sent");
               // MessageBox.Show("Email sent");
               // MessageBoxResult result = MessageBox.Show("Email sent", "Confirmation");


            //ClientScript.RegisterStartupScript(typeof(Page), "myscript", "<script>alert('Email sent');</script>");
            //ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "confirm('Email sent');", true);
            //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "KEY", "alert('Email sent')", true);
            Page.ClientScript.RegisterStartupScript(typeof(string), "alert", "<script>alert('Email sent')</script>");
            Response.Redirect("Multihotelbook.aspx");
Melinda
  • 1
  • 2

1 Answers1

0

This... looks like ASP.NET code. There is no MessageBox in ASP.NET. Notice that you had to fully reference System.Windows.Forms, which I imagine you also had to add as a reference. Windows Forms and ASP.NET are two very different things.

What exactly are you trying to accomplish? Showing a JavaScript alert()? If that's the case then you can just include some additional JavaScript code in the response.

Except... you're also doing this:

Response.Redirect("Multihotelbook.aspx");

Which means that the response to the client is being clobbered by a header which tells the client to go to Multihotelbook.aspx. So the client never sees anything else you're including in the response, basically anything in RegisterStartupScript.

After this code executes, the client is going to end up on Multihotelbook.aspx. Unless there's a JavaScript alert() on that page, the browser won't show one.

One approach you could try is to pass a flag to Multihotelbook.aspx, something like Multihotelbook.aspx?emailSent=true and in the Page_Load of that page check for that value and, if it's set to true, include JavaScript code in the page to show the alert() (probably using RegisterStartupScript like you're already trying).

David
  • 208,112
  • 36
  • 198
  • 279
  • Hi David, thx for ur answer and suggestion. i found the answer to perform both msgbox and redirect to Multihotelbook.aspx ClientScript.RegisterStartupScript(typeof(Page), "myScript", ""); – Melinda Dec 19 '12 at 02:46