string strScriptName = "AlertScript";
string strMessage = "There is an error";
string strScript += strMessage + "')<"
strScript += "/"
strScript += "script>"
if(!Page.IsStartupScriptRegistered(strScriptName))
objPage.RegisterStartupScript(strScriptName, strScript)
Response.Redirect("error.aspx");
If you run the code, you will notice that you will be redirected to the error.aspx WITHOUT being prompted the error message dialog box of "This is an error" because Response.Redirect() forces the browser not to render the HTML (sending a header to client to cause client to redirect to specified URL).
To overcome this problem, replace the Response.Redirect("error.aspx"); with
Response.AppendHeader("refresh","0;Url='error.aspx'");
Instead of redirecting the page, the browser would simply refresh the page within 0 second and "redirecting" to the error.aspx, as specified in the Url parameter.
No comments:
Post a Comment