Wednesday, May 21, 2014

Suppress the Default JavaScript Error When Doing an Ajax Postback

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}

void Application_Error(object sender, EventArgs e)
{
try
{
if (HttpContext.Current.Handler is Page && Request.HttpMethod == "POST")
{
var p = (Page)HttpContext.Current.Handler;
var m = ScriptManager.GetCurrent(p);

if (m != null && m.IsInAsyncPostBack)
{
string script = "alert('There was an error and our technical staff has been notified.\\nPlease try again later.');";
Response.ContentType = "text/plain";
Response.Write(script.Length + "|scriptBlock|ScriptContentNoTags|" + script + "|");
Response.End();
}
else
{
Server.Transfer("~/500.aspx");
}
}

else if (HttpContext.Current.Handler is Page)
{
Server.Transfer("~/500.aspx");
}
}
catch { }
}

No comments:

Post a Comment