Sometime, we need to turn the button off after user clicking to prevent the double actions. Let's say, when I developed 2C2P payment processor, I have to disable the "Confirm" button to avoid the double payment transactions when user click the button once. Otherwise, we will have the complaint from user about duplicated transactions when user might click the button double times since page loading is slow (behind scene, it's processing). The following example show you that it turn the submit button off and show message when it press using server-side script.
Here is button control to add <form> tag.
Put the following code to code-behind as below.
Now, click the button every times, it disable itself and user don't have a chance to press the button double.
![]() |
Disable button after clicking |
Here is button control to add <form> tag.
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" Width="97px" />
Put the following code to code-behind as below.
protected void Page_Load(object sender, EventArgs e)
{
this.Button1.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;"
+ Page.ClientScript.GetPostBackEventReference(this.Button1, ""));
this.Button1.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;"
+ Page.ClientScript.GetPostBackEventReference(this.Button1, ""));
}
protected void Button1_Click(object sender, EventArgs e)
{
//Here go on for click event
//Here go on for click event
}
Now, click the button every times, it disable itself and user don't have a chance to press the button double.
Thank you for this wonderful post, It really nice and informative. Keep sharing!!
ReplyDeleteHadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
German Classes in chennai
android development course in chennai
android course in chennai with placement
android training center in chennai