简体   繁体   English

模块通信在DNN中不起作用

[英]module communication not working in DNN

I am using DNN6 and i creted two modules and tried to connect between them using module communicator, here is my code: 我正在使用DNN6,我创建了两个模块并尝试使用模块通信器连接它们,这是我的代码:


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

but i am getting 'null' in the ModuleCommunication variable? 但我在ModuleCommunication变量中得到'null'?

Are you wrapping the modules in an update panel, (have the supports partial rendering option enabled) in the DNN manifest? 您是否在更新面板中包装模块,(在DNN清单中是否启用了支持部分呈现选项)?

If I recall correctly, IMC won't work via UpdatePanels. 如果我没记错,IMC将不能通过UpdatePanels工作。

From whatever code you have provided, it should work. 从您提供的任何代码,它应该工作。 In order to get help you need to provide code for both IModuleCommunicator and IModuleListener implementation. 为了获得帮助,您需要为IModuleCommunicatorIModuleListener实现提供代码。 But you can review Example implementation here . 但您可以在此处查看示例实现 Let me know if you need more help. 如果您需要更多帮助,请告诉我。

Also if you are not using latest version of dnn, please try testing it by creating of latest dnn instance. 另外,如果您没有使用最新版本的dnn,请尝试通过创建最新的dnn实例来测试它。 Let me know if you need more help. 如果您需要更多帮助,请告诉我。

The answer here is simple, you've forgotten exactly how events work, they are just like any other object, you have to instantiate them. 这里的答案很简单,你已经忘记了事件是如何工作的,它们就像任何其他对象一样,你必须实例化它们。 aka. 又名。

public event ModuleCommunicationEventHandler ModuleCommunication = new ModuleCommunicationEventHandler(SomeStaticMethodThatWillBeCalledByDefault);

To get this working you need to implement the IModuleCommunicator interface. 要实现此功能,您需要实现IModuleCommunicator接口。 Right click on the IModuleCommunicator as showed below and extract the interface. 右键单击IModuleCommunicator,如下所示,并提取界面。

public partial class MyClass: PortalModuleBase, IModuleCommunicator

once extracted the following will be generated 一旦提取,将生成以下内容

 public event ModuleCommunicationEventHandler ModuleCommunication;

I call it from a button click event 我通过按钮点击事件来调用它

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

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

}

wrap the whole thing in a try catch block to catch exceptions......hope this helps 将整个事物包装在try catch块中以捕获异常......希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM