日期:2014-05-18  浏览次数:20625 次

关于点击刷新按钮后重复提交的问题!
现在有一个BUTTON按钮,功能是往数据库中插入一条新的记录,但在提交后,点击IE的刷新按钮后,刚才的数据会再一次提交,这个要怎么解决啊?请教各位大虾。。。。

------解决方案--------------------
有个简单 比较笨的办法 但是很实用

BUTTON事件中处理完成之后 重新跳转到当前页。连数据都帮你清空了
------解决方案--------------------
C# code
protected void Page_Load(object sender, EventArgs e) 
  {
    PostBackOptions options = new PostBackOptions(Button1,string.Empty);

    StringBuilder sb = new StringBuilder();
    if (Button1.CausesValidation && this.GetValidators(Button1.ValidationGroup).Count > 0)
    {
      options.ClientSubmit = true;
      options.PerformValidation = true;
      options.ValidationGroup = Button1.ValidationGroup;

      sb.Append("if (typeof(Page_ClientValidate) == 'function')");
      sb.Append("if(Page_ClientValidate(\"" + Button1.ValidationGroup + "\")==false) return false;");
    }
    if (!string.IsNullOrEmpty(Button1.PostBackUrl))
      options.ActionUrl = HttpUtility.UrlPathEncode(Button1.ResolveClientUrl(Button1.PostBackUrl));
   
    sb.Append("this.disabled = true;");
    sb.Append(ClientScript.GetPostBackEventReference(options));
    sb.Append(";");
    Button1.Attributes.Add("onclick", sb.ToString());
  }


你也可以参考csdn的做法:
<input type="submit" name="bt_Submit" value="提交回复" id="bt_Submit" class="button" />
<script type="text/javascript"> //<![CDATA[
document.getElementById("tb_ReplyBody___Editor").style.width = "700px";
try { document.domain = "csdn.net" } catch (ex) { };
document.getElementById("bt_Submit").onclick = function() {
setTimeout(function() {
var btn = document.getElementById("bt_Submit");
btn.disabled = true;
setTimeout(function() { btn.disabled = false }, 10000);
}, 10);
}
//]]></script>