Disable a submit button during Post Backs

This blog is about, how to restrict multiple button submission or clicks?

Most of the developers facing the issue of how to handle multiple button clicks or submission by user at the same time. 

This can be achieved  by using method ClientScript.GetPostBackEventReference (for more information, refer msdn article).

"Returns a string that can be used in a client event to cause post back to the server. The reference string is defined by 

the specified control that handles the post back and a string argument of additional event information."


Lets start with an sample. Drag n drop three Button control to form. One inside UpdatePanel and the other outside of the UpdatePanel.


#.aspx source

pic1.jpg


Now the code behind part. We will bind this method on Page Load.

Also, am using Thread.Sleep for 5 sec delay.

pic2.jpg


Note: The second button will do a full post back. The third button, we can even attach JavaScript validation check before calling get post back event handler.

Button1:

Button1.gif

Button2: above same button effect, but a full post back will happen.

Button3: first it will show the alert followed by above same button effect.

Button3.gif

Hope this blog helped you. Please post your comments. Sample codes attached for download.
 


Recommended Free Ebook
Similar Articles