C# 模块通信在DNN中不工作

C# 模块通信在DNN中不工作,c#,.net,dotnetnuke,C#,.net,Dotnetnuke,我正在使用DNN6,我创建了两个模块,并尝试使用模块通信器在它们之间连接,以下是我的代码: #region IntermoduleCommunication ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs(); oArgs.Value = Session["ShoppingCart"]; if (ModuleCommunication != null) ModuleCommunication(this

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


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

但是我在ModuleCommunication变量中得到了“null”?

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


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

无论您提供什么代码,它都应该可以工作。为了获得帮助,您需要为
IModuleCommunicator
IModuleListener
实现提供代码。但是你可以。如果你需要更多的帮助,请告诉我


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

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

public event ModuleCommunicationEventHandler ModuleCommunication = new ModuleCommunicationEventHandler(SomeStaticMethodThatWillBeCalledByDefault);

要使其正常工作,您需要实现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块包装整个过程以捕获异常……希望这有帮助

Chris,我正在成功地将值从一个模块传递到另一个模块,但是我发现标签没有使用View.ascx上的文本进行更新。我如何才能强制查看它?