为什么我的表格后,当我禁用提交按钮prevent双击? [英] Why doesn't my form post when I disable the submit button to prevent double clicking?

查看:162
本文介绍了为什么我的表格后,当我禁用提交按钮prevent双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像地球上的每个其他web开发者,我有用户双击提交我的形式按钮的问题。我的理解是,要处理这个问题的传统方式,是第一次点击后立即禁用按钮,但是当我这样做,不发布

Like every other web developer on the planet, I have an issue with users double clicking the submit button on my forms. My understanding is that the conventional way to handle this issue, is to disable the button immediately after the first click, however when I do this, it doesn't post.

我没有做这方面的一些研究,上帝知道有足够的信息,但其他的问题,如禁用表单提交按钮,禁用按钮似乎工作。 禁用按钮提交后似乎有同样的问题,因为我,但有是没有提到如何/如果他解决它。

I did do some research on this, god knows there's enough information, but other questions like Disable button on form submission, disabling the button appears to work. The original poster of Disable button after submit appears to have had the same problem as me, but there is no mention on how/if he resolved it.

下面是关于如何重复它的一些code(在IE8 Beta2的测试,但在IE7中有同样的问题)

Here's some code on how to repeat it (tested in IE8 Beta2, but had same problem in IE7)

我的aspx code

My aspx code

<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<script language="javascript" type="text/javascript">
    function btn_onClick()
    {
    	var chk = document.getElementById("chk");
    	if(chk.checked)
    	{
    		var btn = document.getElementById("btn");
    		btn.disabled = true;
    	}
    }
</script>
<body>
    <form id="form1" runat="server">
    	<asp:Literal ID="lit" Text="--:--:--" runat="server" />
    	<br />
    	<asp:Button ID="btn" Text="Submit" runat="server" />
    	<br />
    	<input type="checkbox" id="chk" />Disable button on first click
    </form>
</body>
</html>

我的CS code

My cs code

using System;

public partial class _Default : System.Web.UI.Page 
{
    protected override void OnInit(EventArgs e)
    {
    	base.OnInit(e);
    	btn.Click += new EventHandler(btn_Click);
    	btn.OnClientClick = "btn_onClick();";
    }

    void btn_Click(object sender, EventArgs e)
    {
    	lit.Text = DateTime.Now.ToString("HH:mm:ss");
    }
}

请注意,当您单击该按钮,回发时,时间被更新。但是,当你选中该复选框,下一次你单击该按钮,该按钮被禁用(如预期),但从来不回发。

Notice that when you click the button, a postback occurs, and the time is updated. But when you check the check box, the next time you click the button, the button is disabled (as expected), but never does the postback.

什么鬼我在这里丢失?

先谢谢了。

推荐答案

我认为你只是缺少这个标签:

I think you're just missing this tag:

UseSubmitBehavior="false"

尝试这样的:

<asp:Button ID="btnUpdate" runat="server" UseSubmitBehavior="false" OnClientClick="if(Page_ClientValidate()) { this.disabled = true; } else {return false;}" Text = "Update" CssClass="button" OnClick="btnUpdate_Click" ValidationGroup="vgNew"/>

说明

这篇关于为什么我的表格后,当我禁用提交按钮prevent双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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