1
  Response.Write("<script>alert('Konaklama Başarıyla Eklendi')</script>");
  string url = "NewAccommodation.aspx?mID=" + mID;
  Response.Redirect(url);

Hi, on the above code, it does not show the alert box because of the code lines after it. How to fix that?

1
  • 1
    You will have to put the message box on the NewAccommodation.aspx page... once you have redirected, nothing else is going to happen on the original page Commented Jun 18, 2012 at 11:11

5 Answers 5

3

Working on your exceedingly limited code, you have two options as I see it...

Redirect to NewAccommodation.aspx and then write the "alert" script from there

Or send the following....

Response.Write("<script type='text/javascript'>")
Response.Write("alert('Konaklama Başarıyla Eklendi');")
Response.Write("document.location.href='NewAccommodation.aspx?mID=" + mID.ToString() + "';")
Response.Write("</script>")
Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome, glad I could help. Knowing the life cycle of the communication between the server and the client (as well as exactly what is going to happen on each side) is key to effective ASP.NET programming
2

Why don't you try this

  string url = "NewAccommodation.aspx?mID=" + mID;
  Response.Redirect(url);

And put this on NewAccommodation.aspx page_load

if(!IsPostBack)
    Response.Write("<script>alert('Konaklama Başarıyla Eklendi')</script>");

2 Comments

Except that if he does it like this he will see the alert every time the page is loaded even if the user did not come with this particular redirect.
string url = "NewAccommodation.aspx?mID=" + mID + "&showmessage=1
1

Response.Redirect sends a header to the browser that causes it to navigate to another URL. As its a header, its in the first part of the response so anything that follows it that isn't also header (like your output) is never handled by the browser.

Insted you can;

Response.Write("<script>alert('Konaklama Başarıyla Eklendi'); location.href='" + url  + "'</script>");

Comments

0

You have two options

  1. Redirect to an URL that knows how to display the alert. You may include an argument in the query string but don't include the script itself in the querystring because it is a security risk.
  2. Do a client side redirect via script after the alert by setting window.location.href property.

Comments

0

You can try

Response.Write("alert('Konaklama Başarıyla Eklendi'); window.location.href='NewAccommodation.aspx?mID=" + mID +"'");

Happy coding!!!

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.