On your form code behind you can catch the error here. I created a subclass of the Exception object and throw that so I know what I'm catching.
Page code:
protected void ObjectDataSource1_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
if (e.Exception.InnerException is MyException)
{
lblErrorMessage.Text = e.Exception.InnerException.Message;
e.ExceptionHandled = true;
}
}
}
Object code:
try
{
// Whatever
}
catch (Exception ex)
{
throw new MyException();
}