模块通信在DNN中不起作用

时间:2012-06-12 14:21:59

标签: c# .net dotnetnuke

我正在使用DNN6并且我创建了两个模块并尝试使用模块通信器连接它们,这是我的代码:


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

但我在ModuleCommunication变量中得到'null'?

4 个答案:

答案 0 :(得分:1)

您是否在更新面板中包装模块,(在DNN清单中是否启用了支持部分呈现选项)?

如果我没记错的话,IMC将无法通过UpdatePanels工作。

答案 1 :(得分:1)

根据您提供的任何代码,它应该有效。为了获得帮助,您需要为IModuleCommunicatorIModuleListener实施提供代码。但你可以review Example implementation here。如果您需要更多帮助,请告诉我。

此外,如果您没有使用最新版本的dnn,请尝试通过创建最新的dnn实例来测试它。如果您需要更多帮助,请告诉我。

答案 2 :(得分:1)

这里的答案很简单,你已经忘记了事件是如何工作的,它们就像任何其他对象一样,你必须实例化它们。又名。

public event ModuleCommunicationEventHandler ModuleCommunication = new ModuleCommunicationEventHandler(SomeStaticMethodThatWillBeCalledByDefault);

答案 3 :(得分: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块中以捕获异常......希望这有助于

相关问题