在此介绍实现防止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
}
}
}
}
这样就可以简单的实现了!!!
这里面还需要,共同日志处理,消息处理等!