复制代码 代码如下:
private bool pageRefreshed = false; //页面是否刷新提交
private bool refreshState = false; //ViewState中暂存的状态
复制代码 代码如下:
protected override void LoadViewState(object savedState)
{
object[] states = (object[])savedState;
base.LoadViewState(states[0]);
refreshState = (bool)states[1];
if(Session["__PAGE_REFRESHED"] == null)
pageRefreshed = false;
else
pageRefreshed = refreshState != (bool)Session["__PAGE_REFRESHED"];
}
protected override object SaveViewState()
{
Session["__PAGE_REFRESHED"] = !refreshState;
object[] states = new object[2];
states[0] = base.SaveViewState();
states[1] = !refreshState;
return states;
}
复制代码 代码如下:
private void Button1_Click(object sender, EventArgs e)
{
if (pageRefreshed )
{
label.Text="this is refreshed function";
}
else
{
label.Text="this is new request function";
}
}
复制代码 代码如下:
<system.web>
<httpModules>
<add
type="RefreshModule.Module, RefreshModule"/>
</httpModules>
</system.web>
复制代码 代码如下:
[Refresh()]
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack && !RefereshHelper.IsPageRefreshed)
{
// do some work with the submitted date
}
else
{
// do some work when the page is loaded with the GET method
}
}
}
新闻热点
疑难解答
图片精选