• 防止2次提交和事件统一管理【转】


    在ASP.NET的应用设计中,有一个好的画面基类很重要,它可以实现如:权限验证,Session管理,共通画面控制等等。
    在此介绍实现防止2次提交和事件统一管理
    1:创建基础页面类
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    namespace WeTest.framework.common
    {
        public class BasePage :Page
        {
            // 处理标记ID
            protected const string SyoRiFlg_NM = "SyoRiFlg_234u19798701872348374534543";

            // 处理函数
            protected virtual void Run_Gen_Act_Cmd(int pintActCmd)
            {
            }

            /// 画面实行函数(2次提交验证)
            protected void Gen_Act_Cmd(int pintActCmd)
            {
                // 处理中验证
            if (!IsSyoRiFlg)
                {
                    // 处理标记设置
                    SetSyoRiFlg();
                    // 业务处理
                    Run_Gen_Act_Cmd(pintActCmd);
                    // 处理标记清空
                    ClearSyoRiFlg();
                }
            }

            // 处理中标记
            public bool IsSyoRiFlg
            {
                get
                {
                    bool blnSyoRi_Flg = false;
                    if(Session[SyoRiFlg_NM] == null)
                    {
                        Session[SyoRiFlg_NM] = blnSyoRi_Flg;
                        return blnSyoRi_Flg;
                    }
                    blnSyoRi_Flg = (bool)Session[SyoRiFlg_NM];
                    return blnSyoRi_Flg;
                }
            }
            /// 业务处理中标记设置
            public void SetSyoRiFlg()
            {
                bool blnSyoRi_Flg = true;
                Session[SyoRiFlg_NM] = blnSyoRi_Flg;
            }
            // 业务处理中标记清空
            public void ClearSyoRiFlg()
            {
                bool blnSyoRi_Flg = false;
                Session[SyoRiFlg_NM] = blnSyoRi_Flg;
            }

        }

    }


    2:创建画面,继承上面的基类:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using WeTest.framework.common;
    namespace WeTest
    {
        // testForm1 概要説明。
        public class testForm1 : BasePage
        {
            protected System.Web.UI.WebControls.Button testBtn1;
        
            private const int ACTIVE_SEARCH = 1;

            private void Page_Load(object sender, System.EventArgs e)
            {
                
            }

            override protected void OnInit(EventArgs e)
            {
                InitializeComponent();
                base.OnInit(e);
            }

            private void InitializeComponent()
            {    
                this.testBtn1.Click += new System.EventHandler(this.testBtn1_Click);
                this.Load += new System.EventHandler(this.Page_Load);
            }

            private void testBtn1_Click(object sender, System.EventArgs e)
           {
                Gen_Act_Cmd(ACTIVE_SEARCH);
            }
            // 处理函数 处理命令
           protected override void Run_Gen_Act_Cmd(int pintActCmd)
            {
                try
                {
                    switch(pintActCmd)
                    {
                        case ACTIVE_SEARCH:
                        {
                            //To Do
                            break;
                        }
                    }
                }
                catch(Exception ex)
                {
                    //Log
                    
                }
            }
        }
    }
    这样就可以简单的实现了!!!
    这里面还需要,共同日志处理,消息处理等!
  • 相关阅读:
    python -- 初始函数 函数的定义,函数的返回值以及函数的参数
    python 文件操作: 文件操作的函数, 模式及常用操作.
    第三节 深入JavaScript
    第二节 JavaScript基础
    第一节 JavaScript概述
    面试大纲
    flask
    面试准备
    数据结构与算法 学习
    Linux学习
  • 原文地址:https://www.cnblogs.com/myssh/p/1493192.html
Copyright © 2020-2023  润新知