在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 on 2012-05-04 11:03  纳米程序员  阅读(212)  评论(0编辑  收藏  举报