增加新记录时ObjectDataSoruce和FormViw中的相关事件使用总结
2007-06-13 11:46
337 查看
首先,当在FormView中按下commandName="Insert"的按钮时,.NET先会执行object data source的OnInserted事件。这个事件有一个ObjectDataSourceStatusEventArgs类型的参数:它有几个属性我们会用到:
1. e.Exception --表示增加时发生的异常对象,如果在调用的目标对象上发生异常,查看InnerException对象以取得更多信息。
2. e.ExceptionHandled --表示是否将异常标记为已处理,如果设为true,异常不会传到后面的事件中去。
3. e.ReturnValue --表示你在object data source上设置的InsertMethod返回的值,可以通过此值检查是否成功。
接着,.NET会执行FormView的OnItemInserted事件,如果前面object data source的ExceptionHandled没有被设为true,那么Exception会传入这个事件中,此事件有一个FormViewInsertedEventArgss类型的参数:它有几个属性我们会用到:
1. e.ExceptionHandled --表示是否将异常标记为已处理,如果设为true,异常不会传到后面的Page.Error事件中去。否则如果定义了Page.Error事件,先执行Page.Error事件,如果Page.Error没有执行Server.ClearError()方法,异常再传入Application_Error事件中去.未定义Page.Error事件处理程序时,直接传入Application_Error事件中。
2. e.KeepInInsertMode --是否保持Insert模式中,通常如果出错,我们会显示一个错误信息,保持在Insert模式方便用户修改
protected override void OnError(EventArgs e)
protected void fvFixingResult_ItemInserted(object sender, FormViewInsertedEventArgs e)
protected void objdsFixingResult_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
//e.ExceptionHandled = true;
LogManager.AddActivity("Add <Fixing Result - ELNZC>", false);
if (e.Exception.InnerException != null && e.Exception.InnerException is FixingDateDuplicatedException)
{
FixingDateDuplicatedException fx = e.Exception.InnerException as FixingDateDuplicatedException;
lblErrorMessage.Text = MessageManager.GetMessage(fx.MessageID, Language).MessageDesc;
}
else
{
lblErrorMessage.Text = MessageManager.GetMessage(SysMessage.COMMON_SAVE_FAILED, Language).MessageDesc;
}
}
else
{
LogManager.AddActivity("Add <Fixing Result - ELNZC>, data key: " + e.ReturnValue);
}
}
1. e.Exception --表示增加时发生的异常对象,如果在调用的目标对象上发生异常,查看InnerException对象以取得更多信息。
2. e.ExceptionHandled --表示是否将异常标记为已处理,如果设为true,异常不会传到后面的事件中去。
3. e.ReturnValue --表示你在object data source上设置的InsertMethod返回的值,可以通过此值检查是否成功。
接着,.NET会执行FormView的OnItemInserted事件,如果前面object data source的ExceptionHandled没有被设为true,那么Exception会传入这个事件中,此事件有一个FormViewInsertedEventArgss类型的参数:它有几个属性我们会用到:
1. e.ExceptionHandled --表示是否将异常标记为已处理,如果设为true,异常不会传到后面的Page.Error事件中去。否则如果定义了Page.Error事件,先执行Page.Error事件,如果Page.Error没有执行Server.ClearError()方法,异常再传入Application_Error事件中去.未定义Page.Error事件处理程序时,直接传入Application_Error事件中。
2. e.KeepInInsertMode --是否保持Insert模式中,通常如果出错,我们会显示一个错误信息,保持在Insert模式方便用户修改
protected override void OnError(EventArgs e)
protected void fvFixingResult_ItemInserted(object sender, FormViewInsertedEventArgs e)
protected void objdsFixingResult_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
//e.ExceptionHandled = true;
LogManager.AddActivity("Add <Fixing Result - ELNZC>", false);
if (e.Exception.InnerException != null && e.Exception.InnerException is FixingDateDuplicatedException)
{
FixingDateDuplicatedException fx = e.Exception.InnerException as FixingDateDuplicatedException;
lblErrorMessage.Text = MessageManager.GetMessage(fx.MessageID, Language).MessageDesc;
}
else
{
lblErrorMessage.Text = MessageManager.GetMessage(SysMessage.COMMON_SAVE_FAILED, Language).MessageDesc;
}
}
else
{
LogManager.AddActivity("Add <Fixing Result - ELNZC>, data key: " + e.ReturnValue);
}
}
相关文章推荐
- javascript 事件相关使用总结01
- Redis总结(五)缓存雪崩和缓存穿透等问题 Web API系列(三)统一异常处理 C#总结(一)AutoResetEvent的使用介绍(用AutoResetEvent实现同步) C#总结(二)事件Event 介绍总结 C#总结(三)DataGridView增加全选列 Web API系列(二)接口安全和参数校验 RabbitMQ学习系列(六): RabbitMQ 高可用集群
- Unity3D中uGUI事件系统简述及使用方法总结
- cocos2dx-jsb及Cocosbuilder使用相关问题处理记录
- IntelliJ IDEA12.1.1 使用 相关记录
- [置顶] API相关工作过往的总结之Sandcastle简要使用介绍
- CocoaPods 使用总结记录
- 总结Selenium WebDriver中一些鼠标和键盘事件的使用
- 在Web Service中使用SPS Object 的相关问题?
- PackageManager()的使用列举相关的事件 ActivityManage
- tensorflow object detection API 使用记录2
- 使用Intel编译器(1)并行化(3)自动并行化相关的选项和总结
- vue.js中生命周期与相关函数的使用总结
- jQuery各种选择器、节点、事件,删除、复制、插入元素的使用方法总结
- 初次使用Ajax.net,总结下心得并记录下来
- Storm使用到的相关技术总结
- Redis使用记录-相关资料汇总
- RecyclerView使用,RecyclerView使用,增加一个item,删除一个item,更新数据,item点击事件
- IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结
- 微信、微博、qq第三方申请接口使用相关事项总结