Redirect to Error Page Using JavaScript

My readers enquired that how to rehuffle the yellow page on web.
The Yellow page appears when Web-Site got any runtime error.

I always suggested to supercede the Yellow-Page. Try the following code :

namespace AStepAhead.redirectErrorPage
public class redirectErrorPage
public redirectErrorPage()
String strDomainName = "";
//Write you coding here
catch (Exception ex)
SystemFramework.ApplicationLog.WriteError("Error : " + ex.ToString());
//Redircet you main page to error page
Response.Write("<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">\n");
Response.Write("if (window.opener != null) {\n");
Response.Write("window.opener.location.href = '" + "https://" + strDomainName + "/errorpage.aspx?Error=" + Server.UrlEncode(ex.ToString()) + "';\n");
Response.Write("} else { \n");
Response.Write("window.location.href = '" + "https://" + strDomainName + "/errorpage.aspx?Error=" + Server.UrlEncode(ex.ToString()) + "';\n");
Response.Write("} \n");


Now, in error page, read ErrorString and show to the users.

Step(s): Followings are the steps to perform above:

1. Create an Error Page and named it as errorpage.aspx.
2. Read Error string at Page_load
3. Write above code in your Web Page.

After above, whenever any runtime exception occured, your user will see a maintained / designed error page.

Article by Gaurav Aroraa
Gaurav is a Microsoft Technology Specialist professional. He has awarded lifetime membership from Computer Society of India (CSI). He has more than 13yrs of experience in the industry. Currently, he is working in the capacity of Solution Architect with an MNC. He is serving to the various communities since 1999.

Follow Gaurav Aroraa or read 157 articles authored by Gaurav Aroraa


Author: Shuby27 Dec 2008 Member Level: Bronze   Points : 1

A great idea to show error page instead of system geneerated yellow error page. I adapt this in my own project

keep it up

Best of luck


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: