ASP.Net防止页面刷新重复提交

在asp.net中页面刷新则会出现重复提交问题

解决方法一:提交完成后跳转至新页面

解决方法二:网站找的,代码如下

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


使用方法

if (IsRefresh)
{
return;
}



posted @ 2012-03-31 12:09  WebApi  阅读(499)  评论(0编辑  收藏  举报
CopyRight © 博客园 WebAPI