Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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:
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 19-Apr-13 0:54am
Edited 19-Apr-13 1:03am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
_Amy at 19-Apr-13 6:05am
   
+5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
    location.replace(newURL)
    to send user to Configuration.aspx.
 
Regards,
  Permalink  

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100