Double PostBack inside UpdatePanel
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, 开发者_C百科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).
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>
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?
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.
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
make no sense but works
精彩评论