I have a GridView with a LinqDataSource attached to it. I want to control the "Row not found or changed" exception alerting the user that the record he's trying to update has been modified by someone else.
At the 'OnUpdated' method of the LinqDataSource, I can handle the exception by doing this:
protected void LDS_Updated(object sender, LinqDataSourceStatusEventArgs e)
{
if (e.Exception != null && e.Exception.HResult == -2146233088)
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "Row not found or changed", "alert('Row not found or changed');", true);
}
}
The problem is that a JavaScript exception is raised and the alert does not appear, as you can see in my Firebug console:
https://i.sstatic.net/18F30.png
How can I avoid that JavaScript error and show my 'alert'? Thanks in advance!
Set the e.ExceptionHandled
to true.
Here you're just doing something in case of exception, but you don't actually handle it, you don't tell the stack that you've handled this case, all is well, no need to worry about it.
By the way, I would not check the HResult code of the exception (which seems flaky), but I would check the type of the exception. Not sure if it's the best method, though.