[英]Conflicting RaiseCallbackEvents of ICallbackEventHandler when using a User Control on an ASP.Net Page
Hi and thanks for reading. 嗨,谢谢您的阅读。
I am using the ICallbackEventHandler interface to do some client-side processing in an ASP.Net page (VS 2005). 我正在使用ICallbackEventHandler接口在ASP.Net页(VS 2005)中进行一些客户端处理。 Everything works as expected except under the following situation.
除以下情况外,其他所有操作均按预期进行。 I created a User Control (.ascx) that also uses ICallbackEventHandler and placed it on the aforementioned ASP.Net page.
我创建了一个也使用ICallbackEventHandler的用户控件(.ascx),并将其放置在上述ASP.Net页上。 Now, the RaiseCallbackEvent fires on the User Control but not on the ASP.Net page.
现在,RaiseCallbackEvent在用户控件上触发,但不在ASP.Net页面上触发。 In other words, it doesn't fire in both places.
换句话说,它不会在两个地方都触发。 Has anyone else encountered this and have a solution?
还有其他人遇到过这种情况并有解决方案吗?
To reproduce, just create an ASP.Net page that uses ICallbackEventHandler, a User Control that uses ICallbackEventHandler and place it on the ASP.Net page and you'll see that the RaiseCallbackEvent fires in the User Control but not in the ASP.Net page. 要重现,只需创建一个使用ICallbackEventHandler的ASP.Net页面,一个使用ICallbackEventHandler的用户控件并将其放置在ASP.Net页面上,您会看到RaiseCallbackEvent在用户控件中触发,但在ASP.Net页面中不触发。
Thanks! 谢谢!
在ASP标记页面的顶部,您必须打开: EnableEventValidation="false"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Form.aspx.cs" Inherits="Form" DynamicMasterPageFile="~masterurl/default.master" EnableEventValidation="false" %>
When the ICallback event fires you'll need to raise your own event on the control so the page can be notified. 触发ICallback事件时,您需要在控件上引发自己的事件,以便可以通知页面。 The other option is implement an interface on your page and require that the user control is hosted on a page that implements the interface.
另一个选项是在页面上实现界面,并要求用户控件托管在实现该界面的页面上。 Once you've done the latter you can cast your page as the interface and gain access to the interface properties and methods.
完成后者后,您可以将页面转换为界面,并访问界面属性和方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.