ASP.NET: Postback processed without events being fired

╄→尐↘猪︶ㄣ 提交于 2019-12-06 16:00:17

A couple problems here. Number one, there is no IsPostBack check, which means you're databinding on every load... this is bound to cause some problems, including events not firing. Second, you are calling DoDataBind() twice on every load because you're calling it in OnLoad and Render. Why?

Bind the data ONCE... and then again in reaction to events (if needed).

Other issue... don't bind events to ImageButton in the template fields. This is generally not going to work. Use the ItemCommand event and CommandName/CommandArgument values.

Finally... one last question for you... have you done a comparison (windiff or other tool) on the HTML rendered by the entire page on the first load, and then subsequent loads? Are they EXACTLY the same? Or is there a slight difference... in a control name or PostBack reference?

Well I think the event dispatching happens after page load. In this case, its going to try to run against the controls created by your first data-binding attempt. This controls will have different IDs than when they are recreated later. I'd guess ASP.NET is trying to map the incoming events to a control, not finding a control, and then thats it.

I recommend taking captures of what is in the actual post.

ASP.NET is pretty crummy when it comes to event binding and dynamically created controls. Have fun.

Since in my opinion this is a partial answer, I re-post it this way:

  • If I use normal Buttons instead of ImageButtons (in the exact same place, i.e. still using MyItemTemplate but instantiating Button instead of ImageButton in "InstantiateIn", it works fine.

  • If I assert that DoDataBind() is always executed twice before sending the content to the client, it works fine with ImageButtons.

Still puzzled, but whatever...

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