Double PostBack inside UpdatePanel

主宰稳场 提交于 2019-12-08 04:07:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!