点击刷新时F#validate重复上一次PostBack(F5)

我有一个生成文件的webform,但当我点击产生回发的按钮生成文件一旦完成,如果我按下刷新(F5)页面重新提交回发并重新生成文件,有任何方法来validation它和向用户显示消息或只是没有!

谢谢 :)

更简单的方法是使用Post Rediret Get模式。

http://en.wikipedia.org/wiki/Post/Redirect/Get

请务必查看该Wikipedia文章的外部链接。

浏览器应该警告他们,如果他们在已经回发的页面上点击刷新。 我如何处理它虽然是在会话跟踪我做了什么所以我不重复某些行动。 一个简单的旗帜就足够了。

检查回发逻辑中是否存在相关文件,如果该文件尚不存在,则仅创建该文件:

if (false == System.IO.File.Exists(filename)) { // create the file } else { // do whatever you do when the file already exists } 

我为这个问题写了一个解决方案,如果有人需要的话。

  protected void Page_Load(object sender, System.EventArgs e) { /*******/ //Validate if the user Refresh the webform. //U will need:: //A global private variable called ""private bool isRefresh = false;"" //a global publica variable called ""public int refreshValue = 0;"" //a html control before  tag: """" int postRefreshValue = 0; refreshValue = SII.Utils.convert.ToInt(Request.Form["ValidateRefresh"]); //u can use a int.parse() if (refreshValue == 0) Session["ValidateRefresh"] = 0; postRefreshValue = SII.Utils.convert.ToInt(Session["ValidateRefresh"]); //can use a int.parse() if (refreshValue < postRefreshValue) isRefresh = true; Session["ValidateRefresh"] = postRefreshValue + 1; refreshValue = SII.Utils.convert.ToInt(Session["ValidateRefresh"]); //can use a int.parse() /********/ if (!IsPostBack) { //your code } } 

你只需要评估:

 if (!isRefresh) PostFile(); else { //Error msg you are refreshing }