感谢您的评论并对不起我的错误,我在以下网址找到了此代码:http: //www.codeproject.com/KB/aspnet/Detecting_Refresh.aspx 此次测试;)
private bool _refreshState; private bool _isRefresh; protected override void LoadViewState(object savedState) { object[] AllStates = (object[])savedState; base.LoadViewState(AllStates[0]); _refreshState = bool.Parse(AllStates[1].ToString()); _isRefresh = _refreshState == bool.Parse(Session["__ISREFRESH"].ToString()); } protected override object SaveViewState() { Session["__ISREFRESH"] = _refreshState; object[] AllStates = new object[2]; AllStates[0] = base.SaveViewState(); AllStates[1] = !(_refreshState); return AllStates; } protected void btn_Click(object sender, EventArgs e) { if (!_isRefresh) Response.Write(DateTime.Now.Millisecond.ToString()); }