ASP.Net防止页面刷新重复提交
生活随笔
收集整理的這篇文章主要介紹了
ASP.Net防止页面刷新重复提交
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在asp.net中頁面刷新則會出現重復提交問題
{
public class Page : System.Web.UI.Page
{
private bool _refreshState;
private bool _isRefresh;
public bool IsRefresh
{
get
{
return _isRefresh;
}
}
protected override void LoadViewState(object savedState)
{
object[] allStates = (object[]) savedState;
base.LoadViewState(allStates[0]);
_refreshState = (bool) allStates[1];
_isRefresh = _refreshState == (bool) Session["__ISREFRESH"];
}
protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] allStates = new object[2];
allStates[0] = base.SaveViewState();
allStates[1] = !_refreshState;
return allStates;
}
}
}
{
return;
}
解決方法一:提交完成后跳轉至新頁面
解決方法二:網站找的,代碼如下
namespace StevenBey.Web.UI{
public class Page : System.Web.UI.Page
{
private bool _refreshState;
private bool _isRefresh;
public bool IsRefresh
{
get
{
return _isRefresh;
}
}
protected override void LoadViewState(object savedState)
{
object[] allStates = (object[]) savedState;
base.LoadViewState(allStates[0]);
_refreshState = (bool) allStates[1];
_isRefresh = _refreshState == (bool) Session["__ISREFRESH"];
}
protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] allStates = new object[2];
allStates[0] = base.SaveViewState();
allStates[1] = !_refreshState;
return allStates;
}
}
}
使用方法
{
return;
}
轉載于:https://www.cnblogs.com/wifi/articles/2482366.html
總結
以上是生活随笔為你收集整理的ASP.Net防止页面刷新重复提交的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: XenApp Command Line参
- 下一篇: 你必须要知道的架构知识~第二章 代码是否