2012-06-12 61 views
1

我使用DNN6和我creted兩個模塊,並試圖用模塊溝通它們之間的連接不工作,這是我的代碼:模塊通訊在DNN


#region IntermoduleCommunication 
ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs(); 
oArgs.Value = Session["ShoppingCart"]; 
if (ModuleCommunication != null) 
ModuleCommunication(this, oArgs); 
#endregion 

,但我在ModuleCommunication越來越「空」變量?

回答

1

是否將模塊包裝在DNN清單中的更新面板中(啓用了支持部分渲染選項)?

如果我沒有記錯,IMC將無法通過UpdatePanels工作。

+0

克里斯,我從一個模塊成功地將值傳遞給另一個,但我標籤d oes沒有得到View.ascx文本的更新。我該如何強制查看它? – alwaysVBNET

1

從你提供的任何代碼,它應該工作。爲了獲得幫助,您需要爲IModuleCommunicatorIModuleListener實施提供代碼。但你可以review Example implementation here。讓我知道你是否需要更多幫助。

此外,如果您不使用最新版本的dnn,請嘗試通過創建最新的dnn實例來測試它。讓我知道你是否需要更多幫助。

1

答案在這裏很簡單,你已經完全忘記了事件是如何工作的,它們就像任何其他對象一樣,你必須實例化它們。又名。

public event ModuleCommunicationEventHandler ModuleCommunication = new ModuleCommunicationEventHandler(SomeStaticMethodThatWillBeCalledByDefault); 
1

爲了得到這個工作,你需要實現IModuleCommunicator接口。右鍵單擊IModuleCommunicator,如下所示並提取界面。

public partial class MyClass: PortalModuleBase, IModuleCommunicator 

一次提取下面會產生

public event ModuleCommunicationEventHandler ModuleCommunication; 

我把它從一個按鈕單擊事件

protected void btn1_Click(Object sender, EventArgs e) 
     { 
    if (ModuleCommunication == null) return; 

       ModuleCommunicationEventArgs args = new ModuleCommunicationEventArgs(); 
       args.Sender = this.GetType().ToString(); ; 
       args.Target = "MyTarget"; 

} 

包住整個事情在try catch塊捕獲異常.. ....希望這可以幫助