Click here to Skip to main content
11,924,487 members (56,611 online)
Rate this:
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>");
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?
Posted 19-Apr-13 0:54am
Edited 19-Apr-13 1:03am
Rate this: bad
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)

If you have any further problem, So please let me know.
_Amy 19-Apr-13 6:05am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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
    to send user to Configuration.aspx.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151125.3 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2015
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