在回发期间禁用 ASP.NET 动态按钮单击事件,然后再启用它
我正在代码中动态创建一个按钮并向其附加单击事件。但是,我必须防止人们在进程正在进行时单击它。因此,当单击一次时,应将其禁用,而当进程结束时,应启用它。我怎样才能做到这一点?
谢谢。
I am creating a button dynamically in my code and attaching a click event to it. However I have to prevent people to click it while there is a process going on. So when it is clicked once, it should be disabled and when the process ends it should be enabled. How can I do that?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在单击按钮时通过 ajax 进行处理 -
1. 处理开始时禁用按钮
2. 处理完成后启用按钮
如果按钮回发,最好的方法是通过 javascript 单击按钮时禁用按钮 [我不会建议仅使用 jquery 来完成此特定任务]。由于回发后该按钮将像之前一样启用,因此您无需担心启用问题。
希望这有帮助。
If you are processing via ajax when the button is clicked-
1. Disable the button when processing starts
2. Enable the button after processing completes
If the button postbacks, the best way is to disable the button when it is clicked via javascript [I won't suggest jquery just for this particular task]. Since after postback the button will be enabled as it was earlier, you don't need to worry about enabling.
Hope this helps.
我会在按钮周围使用 UpdatePanel。单击后,您可以在服务器端禁用该按钮。如果您的外部进程返回了结果,请在更新面板上使用触发器,该触发器每 x 秒查看一次。我建议您将长时间运行的进程外包到 Windows 服务中。
I would use an UpdatePanel arround the button. On click you can serverside disable the button. Use a trigger on the updatepanel that looks every x seconds if your extern process has returned a result. And I would advise you to source out long running processes into a windows service.
onclick="this.enabled=false" 将其从后面的代码添加到控件中
btnAdd.Attributes.Add("onclick", "this.enabled=false;");
此链接详细解释了http://encosia。 com/2007/04/17/disable-a-button-control-during-postback/
onclick="this.enabled=false" add this from your code behind to your control
btnAdd.Attributes.Add("onclick", "this.enabled=false;");
This link explains in detail http://encosia.com/2007/04/17/disable-a-button-control-during-postback/