限制多次单击提交按钮 [英] Restrict multiple click on submit button

查看:68
本文介绍了限制多次单击提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
在一个页面中,有1个文本框和1个tinyMCE用于覆盖率文本框.最初,我同时使用了ASP需求验证,这是一个问题,尽管tinyMCE包含一些值,但它给出了验证错误,有时对文本框的验证也不起作用.

因此,我更改了该代码,并将代码放入.cs文件中.就像if(txtMessageContent.Value ==")一样,它将显示一条错误消息,请输入您的文本. txtMessageContent是tinyMCE.

现在,编写消息后,当我多次单击提交"按钮时,它将多次发布消息,但是我需要发送一次.

我使用了javascript来禁用按钮,但是问题是,如果它进入下面给出的代码的第一个else循环或第二个else循环,则Button会禁用.这也是不可取的.

有什么想法.

Hi every one,
In a page there are 1 textbox and 1 tinyMCE for reach text box. At first I used asp requirement validation for both of that, there was a problem for that though that tinyMCE contains some value it gave the validation errors and sometimes the validation for textbox was not also working.

So, I changed that one and put the code in .cs file. like if (txtMessageContent.Value == " ") it will give an error message please enter your text. txtMessageContent is tinyMCE.

Now after writing message when I click on submit button for multiple times it posts the message for multiple times, but I need to send it once.

I used the javascript to disable the button but the problem is Button disables if it comes into the first else loop or second else loop in the code given below. That is also not desirable.

Any idea please.

if (txtMessageContent.Value != "")
{
    if (txtMessageSubject.Text != "")
    {
        //Codes
    }
    else
    {
        lblErrorMessage.Text = "Please type subject";
    }
}
else
{
    lblErrorMessage.Text = "Please type your message.";
}

推荐答案

嗯,与其他答案类似,但工作流程却很正常.

只需将按钮的OnClientClick 绑定到JavaScript方法即可.假设DisableMe();
Well, something similar to other answer but a little normal workflow.

Just tie a OnClientClick of the button to a JavaScript method. Let say, DisableMe();
// JS method
function DisableMe()
{
  btnSubmit.disabled = true;
}


现在,在服务器端,让btnSumit代码执行.完成所有操作后,将最后一行作为btnSubmit.Enable = true;

这就是单击提交"按钮的那一刻,它将被禁用,并且一旦在服务器端完成了提交"按钮中定义的所有操作,该按钮就会重新启用.


And now, on server side, let the btnSumit code execute. Once all done, put the last line as btnSubmit.Enable = true;

This was, the moment you click the submit button, it wil get disabled and once all the operation defined in the submit button finishes on server side, the button gets enabled back.


您应该将在函数中使用
setTimeout()<br />


调用它 喜欢:


Like:

function submitClick()
{
  btnSubmit.enabled = false;
  setTimeout(''doSubmit();'', 50);
}

function doSubmit()
{
  // Your submit code
}



这样,您可以给浏览器一些时间来更新屏幕并实际禁用按钮.

祝你好运!



This way you give the browser some time to update the screen and to actually disable the button.

Good luck!


这篇关于限制多次单击提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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