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

        }
  • 相关阅读:
    “零接触”新需求,如何快速实现体温检测数字化管控方案?
    AR公共安全及应急指挥中的应用 | TVP思享
    当模板方法遇到了委托函数,你的代码又可以精简了
    为什么要用内插字符串代替string.format
    如何让多个不同类型的后端网站用一个nginx进行反向代理实际场景分析
    8天入门docker系列 —— 第八天 让程序跑在swarm集群上
    8天入门docker系列 —— 第七天 让你的container实现跨主机访问
    8天入门docker系列 —— 第六天 搭建自己的私有镜像仓库Registry
    8天入门docker系列 —— 第五天 使用aspnetcore小案例熟悉容器互联和docker-compose一键部署
    8天入门docker系列 —— 第四天 使用aspnetcore小案例熟悉端口映射和挂载目录
  • 原文地址:https://www.cnblogs.com/rockniu/p/781615.html
Copyright © 2011-2022 走看看