DotNetNuke:将数据从一个模块传递到另一个模块

DotNetNuke : Pass a data from one module to another module

我正在使用 DotNetNuke 逐个模块开发一个网站。 在一个页面(选项卡)中,我有 3 个模块。 2个模块是同一个模块,都是表单模块,但是我给它取了不同的名字(Section A和Section B)。

在我的 Button 模块中,它涉及 A 部分和 B 部分的处理,我如何将数据从具有 A 部分和 B 部分的表单模块传递到同一页面(选项卡)内的 Button 模块?

为此,您需要 IModuleCommunicatorIModuleListener 接口。

在将发送数据的模块上:

public partial class View : Module1, IModuleCommunicator
{
    public event ModuleCommunicationEventHandler ModuleCommunication;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            sendDataToOtherModule("This is a test.");
        }
        catch (Exception ex)
        {
            Exceptions.ProcessModuleLoadException(this, ex);
        }
    }

    public void sendDataToOtherModule(string valueToSend)
    {
        ModuleCommunicationEventArgs mcea = new ModuleCommunicationEventArgs();

        mcea.Target = "TheOtherModule";
        mcea.Value = valueToSend;

        ModuleCommunication(this, mcea);
    }
}

在将接收数据的模块上

但是您可以在每个模块中使用此代码并检查 Target

public partial class View : Module2, IModuleListener
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //module code
        }
        catch (Exception ex)
        {
            Exceptions.ProcessModuleLoadException(this, ex);
        }
    }

    public void OnModuleCommunication(object sender, ModuleCommunicationEventArgs e)
    {
        if (e.Target == "TheOtherModule")
        {
            Label1.Text = e.Value.ToString();
        }
    }
}

在两个模块上添加 using DotNetNuke.Entities.Modules.Communications