For buttons such as "add", "Submit", "save", and "Update", you must load the script during page initialization, prevent repeated clicks. For example:
Protected VoidPage_load (ObjectSender,EventargsE)
{
//. Net1.1
Button1.attributes. Add ("Onclick","This. Disabled = true ;"+This. Getpostbackeventreference (This. Button1 ));
//. NET 2.0 or above
Button1.attributes. Add ("Onclick","This. Disabled = true ;"+This. Clientscript. getpostbackeventreference (button1,""));
}
For testing, we can create a page and add a btnadd button.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "addandedituser. aspx. cs" inherits = "adduser" %> <HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Add and Edit page example </title>
</Head>
<Body>
<Form ID = "frmmain" runat = "server">
<Asp: button id = "btnadd" runat = "server" cssclass = "input-button-save" onclick = "btnadd_click">
</ASP: button>
</Form>
</Body>
</Html>
/*----------------------------------------------------------------
Using system;
Using system. collections;
Using system. configuration;
Using system. Data;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Public partial class adduser: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Btnadd. Attributes. Add ("onclick", "This. Disabled = true;" + this. clientscript. getpostbackeventreference (btnadd ,""));
}
Protected void btnadd_click (Object sender, eventargs E)
{
// Simulate network congestion for 5 seconds
System. Threading. thread. Sleep (5000 );
}
}
It can be seen that when the button is clicked, it takes five seconds to click. That is, the button can only be used after the page is resent. This effectively prevents the user from repeatedly clicking the button, resulting in multiple submissions!