比如DetailView我绑定了一个Insert操作,但是可能抛错,我要在哪里截获这个错误并进行错误提示
1、如果你想在代码级别用try catch 的方式来截获 那是没有的 因为根本没有代码
2、方式a:采用事件方式 DetailView的ItemInserted事件处理
protected void dvChargeDef_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
Exception ex = e.Exception;
}
{
Exception ex = e.Exception;
}
在insert操作结束后可以获取这个异常,同理update和delete
3、方式b 重写页面的onError事件,可以获取
protected override void OnError(EventArgs e)
{
base.OnError(e);
Exception ex = HttpContext.Current.Server.GetLastError().GetBaseException();
if (ex != null)
{
//handle it
}
}
{
base.OnError(e);
Exception ex = HttpContext.Current.Server.GetLastError().GetBaseException();
if (ex != null)
{
//handle it
}
}