zoukankan      html  css  js  c++  java
  • 增加新记录时ObjectDataSoruce和FormViw中的相关事件使用总结

    首先,当在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)
        
    {
            
    //If fvFixingResult_ItemInserted and objdsFixingResult_Inserted
            
    //didn't set ExceptionHandled = true, this event will be called.
            Exception ex = Server.GetLastError();
            
    if (ex != null)
            
    {
                lblErrorMessage.Text 
    = ex.Message;
            }

            Server.ClearError();
        }


        
    protected void fvFixingResult_ItemInserted(object sender, FormViewInsertedEventArgs e)
        
    {
            
    if (!e.ExceptionHandled && e.Exception != null)
            
    {
                e.ExceptionHandled 
    = true;
                e.KeepInInsertMode 
    = true;
            }

            
    else
            
    {
                CloseWindow();
            }

        }


        
    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);
            }

        }
  • 相关阅读:
    揭秘!阿里实时数仓分布式事务Scale Out设计
    ElementUI中使用el-time-picker向SpringBoot传输24小时制时间参数以及数据库中怎样存储
    Vue中实现清空数组和清空el-table
    Vue中foreach数组与js中遍历数组的写法
    Vue中向js中传递参数并在js中定义对象并转换参数
    若依管理系统导出Excel时添加没有的列和关联码表显示中文进行导出
    MyBatis中传递数组参数和List参数时if-test判空和判断长度的写法
    ElementUI中显示是否以及SpringBoot中怎样存储实体类属性和数据库怎样设计字段
    ElementUI中的el-form怎样格式化显示1和0为是和否
    Vue中通过Axios向SpringBoot发送get和post请求
  • 原文地址:https://www.cnblogs.com/rockniu/p/781615.html
Copyright © 2011-2022 走看看