Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On my event, i need to do some validation and then either let
them proceed, or display a error message and boot them back to the
previous page. Here is the code:
C#
Response.Write("<script>alert('Error Message here');</script>");
Response.Redirect("Configuration.aspx");

Problem is that if I call Response.Redirect to move them to the previous
page, the Response.Write gets eaten. How do I solve this issue?
thanks!
Posted
Updated 19-Apr-13 0:03am
v2

I don't know why are you using response.redirect()?

Try to use,

Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "alert("Error message");", true)
Response.Redirect("Configuration.aspx",false);


If you have any further problem, So please let me know.
 
Share this answer
 
Comments
_Amy 19-Apr-13 6:05am    
+5!
Hello,

Response.Redirect should be used before sending any headers/data to the client. Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored. In addition, code execution in the current page is terminated when the Redirect method is processed, so subsequent code in the page will also be ignored. If you really really want to display the error message then you can do it

  1. Store the error message in session with key as the page name (Configuration.aspx) and when the Configuration.aspx runs display it and remove it from session as well
  2. Send a response containing javascript which will show the error and use
    JavaScript
    location.replace(newURL)
    to send user to Configuration.aspx.


Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900