After a lot of searching for a clean way to convey errors to the user from a grid database operation I found the following suggestion:
This worked really well and allowed me to trap Exceptions and then turn them into more user friendly responses. In one case I simply passed on the Exception.Message as the string. But when I tested it by forcing a SQL Error, it didn't work. After hours of experimenting, I eventually found that if the string contained CRLF sequences this meant it was not handled properly by the OnError script on the browser. I fixed this by doing something similar to:
In other words I replaced all the CRLF sequences by br html elements.This works, but it seems to me this is very fragile. So my questions are:
return new HttpStatusCodeResult(int, string)
catch (Exception e)
{
return new HttpStatusCodeResult(550, e.Message.Replace("\r\n", "<
br
/>"));
}
- Is the error with the ASP.Net code or with the Keno UI code?
- If I have missed some fine print somewhere what generalized steps can I take to ensure this works in all cases?
Many thanks