【问题标题】:How to change the standard event handler signature of asp Updatepanel?如何更改 asp Updatepanel 的标准事件处理程序签名?
【发布时间】:2012-01-28 08:55:39
【问题描述】:

我一直使用标准的 Asp.net 控件,除了 AjaxControlToolkit 之外,从来没有遇到过问题。最近我不得不使用非标准 .NET 控件的 Dundas Charting 控件,我必须根据 Dundas 中显示的报告来控制页面的一部分。

很遗憾,Dundas 事件签名无法被 UpdatePanel 识别,并且出现以下错误

说明:

 An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

异常详情:

 System.InvalidOperationException: The 'CommandFired' event on associated control 'chart1' for the trigger in UpdatePanel 'updatepanel1' does not match the standard event handler signature.

所以我想知道是否有可能更改更新面板的处理程序签名?如果是,该怎么做?

【问题讨论】:

  • IMO,事件签名是什么样的?标准事件签名意味着 void 返回类型和两个参数 - object(sender) 和事件参数(类型派生自“EventArgs”)。我觉得 Dundas 不太可能有不同的签名 - 也许问题出在其他地方。

标签: asp.net .net ajax error-handling ajaxcontroltoolkit


【解决方案1】:

看起来CommandFiredEventArgs 类不是从System.EventArgs 派生的,这可能是问题所在。我不会尝试更改 UpdatePanel 期望的签名,而是从 Chart 对象派生一个子类,然后添加您自己的事件,并将您自己的 EventArgs 类作为签名的一部分。然后应该很容易将这些与现有的 Dundas 活动联系起来。

一个非常粗略的示例,无法访问下面的 VisualStudio。此处未编译,请自行整理,但概括了大致思路。

public class CustomChart : Dundas.Charting.WebControl.Chart
{
     public event EventHandler<EventArgs> MyCustomEvent;

     public CustomChart()
     {
          this.CommandFired += SomeMethod;
     }

     private void SomeMethod(object sender, CommandFiredEventHandler args)
     {
          this.OnMyCustomEvent(EventArgs.Empty);
     }

     protected void OnMyCustomEvent(EventArgs args)
     {
         if (this.MyCustomEvent != null)
         {
              this.MyCustomEvent(this, args);
         }
     }
}

【讨论】:

  • 很好的提示,但是'CommandFiredEventArgs'被dundas封印了
  • 我并不是建议您从 Dundas 事件参数中派生。您需要自己创建一个新的 EventArgs 类,该类派生自 System.EventArgs 并将 Dundas 中您需要的任何内容添加到其中。然后,您需要在触发自定义事件时从 Dundas CommandFiredEventArgs 映射到 CustomCommandFiredEventArgs。显然,如果您不需要任何信息,您只需制作签名(对象,EventArgs)并使用 EventArgs.Empty 触发事件。
  • 没问题,让我们知道您的进展情况。
  • 很遗憾,我无法将您的建议付诸实践,所以我的问题仍然存在,您能用示例代码更新您的答案吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多