user1285383
user1285383

Reputation: 73

asp.net Response.Write

  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?

Upvotes: 1

Views: 19741

Answers (5)

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

You can try

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

Happy coding!!!

Upvotes: 0

freefaller
freefaller

Reputation: 19953

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>")

Upvotes: 3

Alex K.
Alex K.

Reputation: 175766

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>");

Upvotes: 1

Stilgar
Stilgar

Reputation: 23551

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.

Upvotes: 0

yogi
yogi

Reputation: 19591

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>");

Upvotes: 2

Related Questions