问题
I have a problem with ASP.NET firing a button click twice. The button is inside an UpdatePanel, but when I click it I get two postbacks, then two button clicks, then two calls to my DAL (in that order). I've never encountered this before, and changing AutoEventWireup to false had no effect. The only workaround I can think of would be to hide the functionality in a web service and handle the complications with jQuery, which I'd rather not do for a small project.
The firebug dumps are below (these both happen from one click).

回答1:
Put the following script on the page after the ScriptManager.
<script type="text/javascript">
var postbackControl = null;
var parm = Sys.WebForms.PageRequestManager.getInstance();
parm.add_beginRequest(BeginRequestHandler);
parm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args)
{
postbackControl = args.get_postBackElement();
postbackControl.disabled = true;
}
function EndRequestHandler(sender, args)
{
postbackControl.disabled = false;
postbackControl = null;
}
</script>
回答2:
Could it be that you've hooked jQuery click()
to the button, which is also implicitly inline hooked to onchange by ASP.NET?
jQuery.change + inline onchange fn() causes fn to execute twice
Or did you check whether you might have hooked the server-side handler twice, both declaratively in markup and imperatively in the code-behind?
回答3:
Bizarrely, this seems to be caused by a dodgy ControlAdapter for buttons which adds a span inside the button tag to make sliding doors work.
回答4:
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
make no sense but works
来源:https://stackoverflow.com/questions/6884134/double-postback-inside-updatepanel