I have a custom class, Customer. I want to show a JQuery message on exception. I am attempting following class but the problem is that Page.Response object is unavailable in a custom class.
How to modify the exception line in below given code? I have a separate class named as: MyErrorHandler, that stores all the methods for error handling. Code of both the classes is given below:
public sealed class Customer
{
public void FillList()
{
try
{
.....
}
catch (Exception ex)
{
MyErrorHandler.GetScript(Page.Response,ex.Message.ToString());
}
}
public static class MyErrorHandler
{
public static void GetScript(System.Web.HttpResponse r, string customErrorMessage)
{
r.Write("<script type='javascript'>$.msg({ content : '" + customErrorMessage + "' });</script>");
}
}
You can use
HttpContext.Current.Response