当点击刷新 (F5) 时,C# 验证重复最后一次回传 [英] C# validate repeat last PostBack when hit Refresh (F5)

查看:54
本文介绍了当点击刷新 (F5) 时,C# 验证重复最后一次回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成文件的网络表单,但是当我单击生成回发的按钮以生成文件时,如果我按刷新 (F5) 完成,页面会重新提交回发并重新生成文件,有任何方法可以验证它并向用户显示一条消息,或者干脆什么都不做!

i have a webform that generates a file, but when i click the button that produces the postback to generate the file Once it finish if i press Refresh (F5) the page resubmit the postback and regenerates the file, there's any way to validate it and show a message to the user or simply DO NOTHING!

谢谢:)

推荐答案

我为这个问题写了一个解决方案,如果有人需要它就在这里.

i wrote a solution for this problem and here it is if anyone needs it.

  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 </form> tag: ""<input type="hidden" name="ValidateRefresh" value="<%= refreshValue %>">""

    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
}

这篇关于当点击刷新 (F5) 时,C# 验证重复最后一次回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆