使用 ModalPopupExtender 和 UpdatePanel 应注意的问题
项目中使用 ASP.NET Ajax,也使用了 AjaxToolkit 中的 ModalPopupExtender 控件。
在开发中遇到了这个错误信息:Sys.InvalidOperationException: Handler was not added through the Sys.UI.domEvent.addHandler method。通过 Google 找到了这个帖子,按照老外的方法搞定了该问题,原文引用如下:
This issue seems to stem from the fact that the ModalPopupExtender is not expecting to have the Ok and Cancel controls in the update panel. Normally, you cannot define and Code Behind for these Buttons click events. So when you Click on these buttons, and they post back to the server, something is broken between the ModalPopupExtender and the buttons. By defining dummy buttons to take their place, it will make the web page stop throwing the javascript exception. Even though the buttons are invisible, and do not do anything.
I hope this helps.
用一句来说:不要将 ModalPopupExtender 控件的 OK 和 Cancel 控件放在 UpdatePanel 中。