-
asp.net防刷新(F5) 禁止重复提交 实例(附完整源码)
实现了用户操作时 刷新导致的重复操作问题。 实现原理如下: 使用一个上下文唯一的票据号,该票据号随页面提交或回发而递增,每当用户与服务器端交互时,代码会提取上次的票据号码并与当前票据号码比较,如果当前票据大于上次的票据,则是提交或回发,否则则识别为刷新。 这种方式会用到HttpMoudel,并在其中操作Session。 使用方法如下: 1、引入dll MsdnExt 压缩包中有2.修改web.config,在 添加以下item: 其中“MsdnModule”是一个名字, “Msdn.RefreshModule”是“Msdn”下的“RefreshModule”类型,“MsdnExt”是程序集的名字 3.引入命名空间 using Msdn; 并修改页面类继承Msdn.Page 4.使用代码 代码: protected void Button1_Click(object sender, EventArgs e) { if (!IsPageRefresh) Response.Write("按钮事件"); else Response.Write("页面刷新");TrackRefreshState();} MSDNPage.cs 核心代码如下:using System;using System.Web.UI;using System.Web;using System.Text;namespace Msdn{ public class Page : System.Web.UI.Page { #region Constants // *********************************************************** // Constants public const string RefreshTicketCounter = "RefreshTicketCounter"; private const string SetFocusFunctionName = "__setFocus"; private const string SetFocusScriptName = "__inputFocusHandler"; // *********************************************************** #endregion // *********************************************************** // Ctor public Page() { m_focusedControl = ""; // Register a PreRender handler this.PreRender = new EventHandler(RefreshPage_PreRender); } // *********************************************************** // ************************************************************** // Indicates if the page is being viewed in response to F5 hit public bool IsPageRefresh { get { object o = HttpContext.Current.Items[RefreshAction.PageRefreshEntry]; if (o == null) return false; return (bool) o; } } // ************************************************************** // ************************************************************** // Increase the internal counter used to generate refresh tickets public void TrackRefreshState() { InitRefreshState(); int ticket = Convert.ToInt32(Session[RefreshTicketCounter]) 1; Session[RefreshTicketCounter] = ticket; } // ************************************************************** // ************************************************************** // Set the control with the input focus public void SetFocus(string ctlId) { m_focusedControl = ctlId; } // ************************************************************** #region Private Members // ************************************************************** // Create the hidden field to store the current request ticket private void SaveRefreshState() { int ticket = Convert.ToInt32(Session[RefreshTicketCounter]) 1; RegisterHiddenField(RefreshAction.CurrentRefreshTicketEntry, ticket.ToString()); } // ************************************************************** // ************************************************************** // Ensure that the ticket counter is initialized private void InitRefreshState() { if (Session[RefreshTicketCounter] == null) Session[RefreshTicketCounter] = 0; } // ************************************************************** // ************************************************************** // Handle the PreRender event private void RefreshPage_PreRender(object sender, EventArgs e) { SaveRefreshState(); AddSetFocusScript(); } // ************************************************************** // ************************************************************** // Add any script code required for the SetFocus feature private void AddSetFocusScript() { if (m_focusedControl == "") return; // Add the script to declare the function // (Only one form in ASP.NET pages) StringBuilder sb = new StringBuilder(""); sb.Append(""); sb.Append("function "); sb.Append(SetFocusFunctionName); sb.Append("(ctl) {"); sb.Append(" if (document.forms[0][ctl] != null)"); sb.Append(" {document.forms[0][ctl].focus();}"); sb.Append("}"); // Add the script to call the function sb.Append(SetFocusFunctionName); sb.Append("(); sb.Append(m_focusedControl); sb.Append();"); // Register the script (names are CASE-SENSITIVE) if (!IsStartupScriptRegistered(SetFocusScriptName)) RegisterStartupScript(SetFocusScriptName, sb.ToString()); } // ************************************************************** #endregion #region Private Properties // *********************************************************** // Private properties private string m_focusedControl; // *********************************************************** #endregion }}
- 2021-03-16 17:39:21下载
- 积分:1
-
10SampleApp-协调器DHT11温湿度采集
说明: 实现zigbee终端节点的电压及温湿度数据的显示与上传,包含温湿度传感器的驱动文件(It realizes the display and upload of voltage and temperature and humidity data of ZigBee terminal node, including the driver file of temperature and humidity sensor.)
- 2020-06-23 10:20:02下载
- 积分:1
-
局域网文件传输
局域网文件传输
- 2014-12-18下载
- 积分:1
-
VISUAL C# 2008 大学教程第一章源码
VISUAL C# 2008 大学教程第一章源码-VISUAL C# 2008 University of Tutorial first chapter source
- 2022-03-20 17:29:37下载
- 积分:1
-
PID-control-simulation-program
使用matlab编写的PID控制仿真程序(Prepared using matlab simulation program PID control)
- 2013-10-15 11:59:58下载
- 积分:1
-
C# 模拟实现SSH命令
C# 模拟实现SSH命令,模拟实现LINUX相关操作,代码中包括了英文注释,代码比较完整,压缩包中还包括了例子和Bin可执行文件,演示效果如截图所示。我看到模拟程序中使用了以下的类库:DiffieHellman.dll、Org.Mentalis.Security.dll、Tamir.SharpSSH.dll。
- 2022-01-26 08:34:51下载
- 积分:1
-
Pemanggilan Database
How to call MS Database to TextBox
- 2020-06-21 00:40:02下载
- 积分:1
-
hcjlu
合成地震记录,MATALB程序,包括合成记录,求反子波,反滤波,求反射系数(Synthetic seismograms, MATALB procedures, including synthetic records, seeking anti-sub-wave, anti filter, find the reflection coefficient)
- 2021-03-03 20:59:32下载
- 积分:1
-
LISTVIEW
WINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEW(WINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEWWINCE LISTVIEW)
- 2011-01-08 21:27:39下载
- 积分:1
-
4
说明: 通过监测工作状态实现带有IIC通讯功能的数据发送接收(to implement the sending and receiving data function of iic
communication )
- 2013-09-29 09:51:55下载
- 积分:1