Click here to Skip to main content
15,886,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me how to prevent multiple clicks for a button. i have to perform only one time not multiple times.
Posted

 
Share this answer
 
Comments
Ankur\m/ 12-Mar-14 8:39am    
Why allow posting twice in the very first place?
Try this:

In Button click event :
C#
Button1.Enabled = false;


In postback
C#
Button1.Enabled = true;
 
Share this answer
 
Comments
Ankur\m/ 12-Mar-14 8:33am    
That, as far as I know, doesn't work. I don't remember correctly but either disabled button won't postback at all or the postaback is caused by the button won't be detectable on the server side. I may be wrong though.
Tom Marvolo Riddle 12-Mar-14 8:41am    
Hi ankur, when the page loads for the first time
if (!IsPostBack)
{
Button1.Enabled = true; //button get enabled
}

after button click event

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Enabled = false; //button get disabled

}

What's wrong in it?please explain
Ankur\m/ 13-Mar-14 4:19am    
Sorry for the late reply. Just logged in to CP.
That is not what user wants. User wants to avoid multiple clicks. Tell me - does it make sense to disable the button after a postback. What if user wants to update something and submit again? I wouldn't show the button at all rather than keeping it disabled after postback if that is ever required.
Tom Marvolo Riddle 13-Mar-14 5:12am    
Sorry for the late reply. Just logged in to CP--No worries

op wrote--I have to perform only one time not multiple times--Thats why i posted this solution.

Thank for the reply Ankur
Ankur\m/ 13-Mar-14 6:16am    
You omitted the very first line of the question (and the subject too). ;)
Please help me how to prevent multiple clicks for a button

I realized that you got the question wrong and that's why I posted a comment.
You can hide the button and show some processing button image instead of it. Google results[^] will give you many other ways along with the code.
 
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