简体   繁体   English

在ASP.Net页面上使用用户控件时,ICallbackEventHandler的RaiseCallbackEvents发生冲突

[英]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.

相关问题 使用 ASP.NET AJAX / ICallbackEventHandler 跟踪状态 - Tracking state using ASP.NET AJAX / ICallbackEventHandler asp.net使用URL路由时用户控件的多个Page_Load事件 - asp.net Multiple Page_Load events for a user control when using URL Routing ASP.NET ICallbackEventHandler和ASP.net Ajax updatepanel - ASP.NET ICallbackEventHandler and ASP.net Ajax updatepanel CSS 与 ASP.NET 表控件冲突 - CSS is conflicting with ASP.NET table control 在用户控件中使用AjaxControlToolkit手风琴控件,该控件动态添加到asp.net中的页面 - Using AjaxControlToolkit Accordion control in User control that dynamically added to page in asp.net 从用户控件刷新asp.net页面到页面顶部 - Refreshing an asp.net page to top of page from user control 从用户控件调用Web服务时,asp.net页为空 - asp.net page is null when a web service is called from user control 在IE7中查看时,母版页上的ASP.NET用户控件呈现在我的主要内容后面 - ASP.NET User control on a master page renders behind my main content when viewed in IE7 在后面的页面代码的Page_Load上引用时,ASP.NET用户控件实例为null - ASP.NET User Control instance is null when referenced on Page_Load on page code behind Asp.net中的用户控件 - User Control In Asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM