2011-12-27 29 views
0

我一直習慣使用標準Asp.net旁邊的控件AjaxControlToolkit並從未遇到過問題。最近我不得不使用Dundas Charting這些控件不是標準的.NET控件,我必須根據Dundas中顯示的報告控制apage的一部分。如何更改asp UpdatePanel的標準事件處理程序簽名?

不幸的是鄧達斯事件簽名不通過的UpdatePanel和的iget以下錯誤認識

說明:

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. 

所以我想知道那有可能改變處理程序忽略updatepanel?如果是的話,該怎麼做?

+0

IMO,事件簽名是什麼樣的?標準事件簽名意味着'void'返回類型和兩個參數 - 對象(發送者)和事件參數(派生自'EventArgs'的類型)。我覺得登打士不太可能有不同的簽名 - 也許問題在別的地方。 – VinayC 2011-12-27 08:55:50

回答

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); 
     } 
    } 
} 
+0

良好的提示隊友,但'CommandFiredEventArgs'被dundas加密 – 2011-12-27 09:13:36

+1

我並不是建議你從Dundas事件參數派生。您需要自己創建一個新的EventArgs類,從System.EventArgs派生並添加到Dundas需要的任何內容中。然後,在啓動自定義事件時,您需要將Dundas CommandFiredEventArgs映射到CustomCommandFiredEventArgs。顯然,如果你不需要任何信息,你可以使用EventArgs.Empty創建簽名(object,EventArgs)並觸發事件。 – starskythehutch 2011-12-27 09:20:54

+0

哇,聽起來很實用。感謝您的描述 – 2011-12-27 09:22:50

相關問題