Why My Web Forms Button Submitted Twice

Editorial illustration.

Originally published 16 June 2023; rewritten and reviewed on 15 October 2026.

While maintaining an ASP.NET Web Forms page, I ran into a classic symptom: clicking the Save button once caused the server-side SaveButton_ServerClick handler to execute twice. In a simple read-only page you might barely notice, but when the handler inserts a record or triggers an email notification, duplicate execution turns into a real data bug.

At first glance the .aspx markup looked harmless—an HTML <button> element with runat="server", type="submit", and onserverclick. Nothing in the code-behind pointed to a loop or a double-bound event. The answer only showed up when I stopped staring at the C# file and inspected what Web Forms actually sent to the browser.

Inspect the rendered HTML and __doPostBack

In standard HTML, <button type="submit"> tells the browser to submit the enclosing <form> natively when clicked. At the same time, adding runat="server" and onserverclick instructs ASP.NET Web Forms to attach a client-side onclick handler that calls __doPostBack('SaveButton', '').

If you open DevTools and look at the rendered markup, it looks similar to this:

<button onclick="__doPostBack('SaveButton','')"
        id="SaveButton"
        type="submit">
    Save
</button>

Because __doPostBack programmatically submits theForm and the browser also continues with its native type="submit" action (unless cancelled), one click can trigger two form submissions in rapid succession. On a fast local machine you might miss the flicker, so checking the browser’s Network tab is essential. Filter by Doc or Fetch/XHR and watch how many POST requests leave the tab on a single click, along with the __EVENTTARGET payload inside Form Data.

Changing the button type to button stopped the native browser submission so only the Web Forms postback ran:

<button runat="server" id="SaveButton"
        type="button"
        onserverclick="SaveButton_ServerClick">
    Save
</button>

Keep in mind that this is specific to mixing an HTML <button> with runat="server" and onserverclick. A standard <asp:Button> renders as <input type="submit"> by default and relies on UseSubmitBehavior="true" (or false when postback scripts are needed) to avoid double firing. Changing type="submit" blindly across every control can break keyboard Enter-key submission inside forms, so always test keyboard navigation and validation groups after the edit.

Check for other double-fire culprits

Before assuming the HTML type attribute is the only problem, rule out the other usual suspects in Web Forms and jQuery-heavy legacy projects:

  • Duplicate event wiring in C#: Check both AutoEventWireup="true" in the @Page directive and explicit += handler attachments in Page_Init or InitializeComponent.
  • Extra JavaScript listeners: A global click handler or a double-included script bundle can call form.submit() alongside the Web Forms postback.
  • Button inside an UpdatePanel: Partial postbacks with custom JS re-binding after Sys.WebForms.PageRequestManager updates often attach click events multiple times unless unbound first.

Protect the server operation anyway

Even after fixing the markup, a user on flaky mobile data or a rushed office worker can still double-click a button or hit Refresh on a POST response. Relying purely on client-side markup for data integrity is fragile.

On the server, follow the Post/Redirect/Get pattern where practical (Response.Redirect(Request.RawUrl, false); Context.ApplicationInstance.CompleteRequest();) so a browser refresh does not replay the POST. For operations that create financial records, bookings, or approvals, enforce uniqueness at the database layer—such as a unique index on a client-generated request token or invoice reference—so a duplicate request fails safely instead of writing a second row.

Whenever a server handler runs twice in Web Forms, trace the path from the user’s click to the Network tab, and from the rendered HTML back to the .aspx source. The server rarely invents a second request on its own; most of the time, the browser was told to send it twice.

Images from the original article

The following images are retained as historical context; interfaces and configuration options may have changed.

Original article image 1: Why My Web Forms Button Submitted Twice