点击刷新时F#validate重复上一次PostBack(F5)
我有一个生成文件的webform,但当我点击产生回发的按钮生成文件一旦完成,如果我按下刷新(F5)页面重新提交回发并重新生成文件,有任何方法来validation它和向用户显示消息或只是没有!
谢谢 :)
浏览器应该警告他们,如果他们在已经回发的页面上点击刷新。 我如何处理它虽然是在会话跟踪我做了什么所以我不重复某些行动。 一个简单的旗帜就足够了。
检查回发逻辑中是否存在相关文件,如果该文件尚不存在,则仅创建该文件:
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 }
- 如何在具有多个服务器的高流量asp.net应用程序中实现随机数流
- XML序列化,编码
- iTextSharp HTMLWorker ParseHTML Tablestyle和PDFStamper
- DateTime ToString(“dd / MM / yyyy”)返回dd.MM.yyyy
- 在unit testing中创建System.Web.Caching.Cache对象
- 如何在IIS 8上运行应用程序时委派Windows身份validation会话?
- 如何根据会话变量以编程方式更改表单操作?
- 在将aspnet 5从beta4升级到beta5之后,似乎无法构建类库项目
- 将自定义代码添加到Entity Framework类