Method 1:
Just add OnClientClick="this.disabled=true;" UseSubmitBehavior="False" to the button front code.
Method 2:
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", this.GetPostBackEventReference(Button1) + ";this.disabled=true;");
}
Note: Do not write it in if (!Page.IsPostBack), otherwise a script error will occur.
The process is to set the button to disabled after clicking it, that is, this.disabled=true.
Although the process is very simple, there is a little trick (I didn’t know it before), which is the UseSubmitBehavior attribute that is not commonly used in the Button control. To make the Button disabled after clicking and the page (form) still needs to be submitted, you must UseSubmitBehavior is set to false, otherwise the page (form) will not be submitted.
MSDN’s explanation of UseSubmitBehavior is:
Use the UseSubmitBehavior attribute to specify whether the Button control uses the client browser’s submission mechanism or the ASP.NET postback mechanism. By default, the value of this property is true, causing the Button control to use the browser's submission mechanism. If false is specified, the ASP.NET page framework adds client script to the page to send the form to the server.
When the UseSubmitBehavior property is false, control developers can use the GetPostBackEventReference method to return Button's client postback event. The string returned by the GetPostBackEventReference method contains the text of the client function call and can be inserted into a client event handler.
For example
When UseSubmitBehavior is false, you will see it in the output Html
__doPostBack('Issue1$doPublishButton',''), which is asp .net added. If UseSubmitBehavior is true, there will be no such sentence and the page (form) will not be submitted.