Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;


Is this the right way? Because the buttons are visible and clickable even after setting value to false.
Posted
Updated 27-Jun-17 20:24pm
v2

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.
 
Share this answer
 
Comments
planetz 26-Jun-17 10:24am    
Can not it be done without cookies?
sachin.vishwa90 26-Jun-17 10:42am    
you can do that by adding some header in your response, basically you have to append something unique in your response and your javascript code should keep on looking for that unique thing in your response and as soon as it finds do the UI changes.
are you facing any issue using cookie?
planetz 26-Jun-17 11:23am    
no, i was looking for some simpler solution!
sachin.vishwa90 27-Jun-17 2:49am    
inform me too, if you find any simpler one. best of luck
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;
           }
       }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900