IE6限制按钮单击一次

时间:2012-03-10 14:46:45

标签: c# asp.net internet-explorer-6

* IE6限制按钮单击一次。 *
我有一个按钮,应该点击一次,当我第一次点击时,我需要运行一些后端逻辑(操作),例如在DB中保存一些数据,发送电子邮件,做一些日志记录,并在这些成功之后操作我需要重定向到另一页。 但我正在使用

btnMakeFO.Visible = false ;

按钮的点击事件后,用户仍然可以点击两次以上。
我也用过:

btnMakeFO.Enabled = false ;

但它也不起作用。

我还在按钮(btnMakeFO_Click)上单击事件处理程序使用了以下内容:

btnMakeFO.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(btnMakeFO, "").ToString());

我已就此问题进行了大量搜索,但我无法找到针对我的问题定制的解决方案。
注意:我在Windows 7 x-64位机器和IE8上进行开发,此处按钮最多被点击两次。在FireFox8中,它只被单击一次。
但是在生产环境中有Windows 2003 Server,Internet Explorer 6,在这个服务器上,按钮可以被点击超过两次,即btnMakeFO按钮可以连续点击大约10到15次。
(生产服务器上的Internet Explorer 6无法升级,因为在较新版本的Internet Explorer中,很少有旧版应用程序无法正常运行。) 我最早要明天解决这个问题。请尽早帮助我。

2 个答案:

答案 0 :(得分:1)

BTW我使用了以下(我从Code Project找到的),它工作得很好,我很满意这个解决方案。

<asp:Button OnClick="btnMakeFO_Click" OnClientClick="clickOnce(this, 'ABC...')">

<script type="text/javascript">
function clickOnce(btn, msg)
{
    // Test if we are doing a validation
    if (typeof(Page_ClientValidate) == 'function')
    {
        // if we are doing a validation, return if it's false
        if (Page_ClientValidate() == false)
        {
            return false;
        }
    }

    // Ensure that the button is not of type "submit"
    if (btn.getAttribute('type') == 'button')
    {
        // The msg attibute is absolutely optional
        // msg will be the text of the button while it's disabled
        if (!msg || (msg='undefined'))
        {
            msg = 'Saving.......';
        }
        btn.value = msg;
        // The magic :D
        btn.disabled = true;
    }
    return true;
}
</script>

答案 1 :(得分:0)

javascript 方法应该有效。

您正在从服务器端注入代码,这可能具有挑战性。在浏览器中运行应用程序和查看源时,您仍应该能够看到结果。您应该在标记中看到javascript,如下所示:

<input type="submit" value="Submit" onclick="this.disabled=true" />

对于ASP.Net,您可能还会尝试OnClientClick事件,您可以将其直接添加到HTML中,而不是从代码隐藏页面中注入它。

相关问题