日期:2014-05-20  浏览次数:20385 次

ispostback
按网页上的刷新按纽!ISPOSTBACK里面的代码就会运行一次呀?请问什么原因是?有什么方法让他不访问吗?

------解决方案--------------------
这个是.net postback 机制的问题
你每执行一次post提交
后 如果没有转向到别的页面 使用IE刷新按钮 就会重新回发刚才的post请求

你可以 用一个 值Session[ "isBack "]或是cookie来判断 是否已经执行了提交
也可以提交后转向到别的页面或Response.Redirect( "你当前的页面 ", true);
或者 禁用客户端缓存

protected void NoCatchOutPage()
{
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1); //DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader( "pragma ", "no-cache ");
HttpContext.Current.Response.AddHeader( "cache-control ", "private ");
HttpContext.Current.Response.CacheControl = "no-cache ";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(true);
}

你的PageLoad里面 第一行 调用这个 函数