Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to disable the control with _dopostback using javascript,
Can any one tell me how to disable the button while i click the button in page
Posted

Use this code onClientClick
JavaScript
<script language="Javascript">
function disabledME()
{
   document.getElementById("btnID").disabled = true;
   return false;
}
</script>

<asp:button id="btnID" text="ClickMe" runat="server" onclientclick="return disabledME();" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
[no name] 15-Mar-12 9:05am    
If you are canceling the response there is no point in having a server control, an html input element will function the same.
Prasad_Kulkarni 15-Mar-12 9:18am    
I thought OP gets the result, so he accepted answer.
[no name] 30-Apr-12 19:26pm    
Doesn't make the solution correct. Just means the OP doesn't know any better either.
Ankur\m/ 19-Jun-12 1:52am    
This won't fire button's click event. Or in other words, server won't know which control caused the postback.
This article explains this scenario very beautifully - Disable a button control during postback.[^]

Dave Ward (author of above article) has replied to the same question here - Disable a button on click[^]

Hope this helps!
 
Share this answer
 
v2
Comments
Ankur\m/ 19-Jun-12 1:56am    
I know this is old, but may guide anyone coming here to the correct direction.
If you want to disable the button after you have clicked and initiated a postback then it won't work, the page is already being processed. If you want to disable it after the postback then in the code-behind set the controls Enabled property. If you want to disable it before postback then use

JavaScript
$(ctrl).attr("disabled", "disabled");
 
Share this answer
 

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