Solution 2 for multiple ASP. NET submissions

Source: Internet
Author: User

For example:
Protected void page_load (Object sender, eventargs E)
{
//. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.