如何在回发期间禁用按钮或页面,并在回发后立即启用它们 [英] How to disable buttons or page during postback in ASP.NET and enable them right after postback

查看:94
本文介绍了如何在回发期间禁用按钮或页面,并在回发后立即启用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



如何在回发期间(在带有c#的asp.net中)禁用页面按钮或页面本身,以便用户无法点击数据处理之间的按钮?



点击按钮时应禁用按钮或页面,并在数据处理后出现错误或成功消息后启用。



谢谢.. !!



我尝试了什么:
单击按钮时




Hello All,

How to disable page buttons or the page itself during postback(in asp.net with c#) so that the user will not be able to click buttons in between data processing?

The button or page should be disabled on button click and will get enabled after data processing with error or success message.

Thank you..!!

What I have tried:

on button click:

btnSave.Enabled = false;
     btnSubmit.Enabled = false;
     btnLogout.Enabled = false;





操作后,错误/成功消息之前:





And after operation, before the error/ success message:

btnSave.Enabled = true;
     btnSubmit.Enabled = true;
     btnLogout.Enabled = true;





这是正确的方法吗?因为即使将值设置为false后按钮也可见并且可点击。



Is this the right way? Because the buttons are visible and clickable even after setting value to false.

推荐答案

兄弟...你很幸运,有一个现成的解决方案可用一点点的javascript

ASP.NET导出Excel - 显示/隐藏加载图像 [ ^ ]

在回发期间显示隐藏加载程序

[ ^ ]

通过这些链接,最好是你要来的第一个知道逻辑。
Bro.. you are lucky, there is a ready made solution available with little bit of javascript
ASP.NET Export Excel - Show/Hide Loading Image[^]
Show hide loader during postback
[^]
Go through these links preferably the first one you will come to know about the logic.


试试

try
<asp:Button Text="text" ID="btnTest" OnClientClick="disableAllButton();" runat="server" OnClick="btnTest_Click" />







function disableAllButton() {
           var buttonsToDisable = [];
           buttonsToDisable.push(<%=Button1.ClientID%>);
           buttonsToDisable.push(<%=Button2.ClientID%>);
           buttonsToDisable.push(<%=Button3.ClientID%>);
           buttonsToDisable.push(<%=btnTest.ClientID%>);
           for (var i = 0; i < buttonsToDisable.length; i++) {
               buttonsToDisable[i].disabled = true;
           }
       }


这篇关于如何在回发期间禁用按钮或页面,并在回发后立即启用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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