Asp.net implementation click the button to set the button to unavailable and submit
Copy codeThe Code is as follows:
<Asp: Button ID = "Button1" runat = "server" Text = "123456" OnClientClick = "this. disabled = true; this. form. submit (); "UseSubmitBehavior =" False "onclick =" button#click "/>
When the client is loaded, restart the operation.
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
Function controlButton (flag ){
Var btnObj = document. getElementById ("Button1 ");
BtnObj. disabled = flag;
}
</Script>
</Head>
<Body onload = "controlButton (false);">
Background code:
Copy codeThe Code is as follows:
Protected void button#click (object sender, EventArgs e)
{
Thread. Sleep (3000 );
Response. Write ("123213 <br> ");
Response. Write ("123213 <br> ");
Response. Write ("123213 <br> ");
}
If there are many buttons on the page, you can use another method:
Background page_load code:
Copy codeThe Code is as follows:
This. BtnSend. Attributes. Add ("onclick", this. GetPostBackEventReference (this. BtnSend) + "; this. disabled = true ;");
Code of the front-end button:
Copy codeThe Code is as follows:
<Asp: button id = "BtnSend" runat = "server" Width = "80px" ForeColor = "White"
Text = "send" BackColor = "#376091" BorderColor = "# FFFFFF" Font-Bold = "True"
Style = "height: 24px" Font-Size = "13px" BorderStyle = "None" OnClick = "BtnSend_Click"> </asp: button>
Because the control's this. after disabled is set, the control is disabled and the background event method cannot be called at the sending back. Therefore, you must use GetPostBackEventReference to call the event Method in the background before calling disabled = true.
ASP. NET UseSubmitBehavior attributes
Definition and usage
UseSubmitBehavior attribute specifies whether the button control uses the submitted function built in the client browser or the postback mechanism of ASP. NET.
This property is set to TRUE if the control uses the browser's submission mechanism. Otherwise, the value is FALSE. The default value is TRUE.
When set to FALSE, ASP. NET adds a client script to upload the form back and forth.
When UseSubmitBehavior is set to false, the control developer can use the GetPostBackEventReference method to return the client sending event of the Button. The string returned by the GetPostBackEventReference method contains the text of the client function call and can be inserted into the client event handler.
Syntax
<Asp: Button UseSubmitBehavior = "TRUE | FALSE" runat = "server"/> instance
The following example uses the postback mechanism of ASP. NET:
Copy codeThe Code is as follows:
<Script runat = "server">
Sub SubmitBtn (obj As Object, e As EventArgs)
LblMsg. Text = "Submitted using the ASP. NET postback mechanic ."
End Sub
</Script>
<Form runat = "server">
Click the button:
<Asp: button id = "Button1" runat = "server"
Text = "Submit" onclick = "SubmitBtn"
UseSubmitBehavior = "FALSE"/>
<Br/>
<Asp: label id = "lblMsg" runat = "server"/>
</Form>