DNN 5 - 无法从自定义模块中的嵌套用户控件获取当前ModuleId

rom*_*n m 7 user-controls dotnetnuke dotnetnuke-5 dotnetnuke-module

我正在为DNN 5编写自定义模块,我需要一个"管理"链接,以便在模块中的每个控件上.我创建了一个新的UserControl("ManagerLink"),它继承自PortalModuleBase,将我的链接放入该控件,并将该控件放在所有主要控件上.

问题是ModuleId和TabId在"ManagerLink"嵌套控件中始终为-1.PortalId工作得很好,我可以通过PortalSettings.ActiveTab.TabID得到一个TabId.

  1. 为什么我不能从"ManagerLink"控件中获取ModuleId和TabId,即使它继承自PortalModuleBase?

  2. 是否有另一种获取ModuleId的方法(相当于PortalSettings.ActiveTab.TabID)

更新2014年:

刚刚看到另一个答案,它比原来更好(并接受它).

如果您使用的是DNN 6及更早版本,请替换ModuleBasePortalModuleBase

rom*_*n m 8

来自DNN论坛的 William Severance 为我回答了这个问题,我也会在这里发布答案.

由于子控件继承自PortalModuleBase,我将在父控件的Page_Load处理程序中执行以下操作

注意:假定ManagerLink是对子控件的引用

VB.NET:

With ManagerLink
    .ModuleConfiguration = Me.ModuleConfiguration
    .LocalResourceFile = Me.LocalResourceFile
End With
Run Code Online (Sandbox Code Playgroud) C#:
protected void Page_Load(System.Object sender, System.EventArgs e)
{
    ManagerLink.ModuleConfiguration = this.ModuleConfiguration;
    ManagerLink.LocalResourceFile = this.LocalResourceFile
}
Run Code Online (Sandbox Code Playgroud)

上面允许子控件使用父级的ModuleConfiguration(包括ModuleId)和LocalResourceFile进行任何本地化.


m.t*_*ett 3

我只是想在这里添加我的 2 美分,使用 @roman-m 的答案并扩展它,

我能够在嵌套控件本身中做到这一点,如下所示:

//fires first in the sequence, calling initialise components
override protected void OnInit(EventArgs e)
{
    InitializeComponent();
    base.OnInit(e);
}

private void InitializeComponent()
{
    this.Load += new System.EventHandler(this.Page_Load);
    //this binds a handler to the parent's init event
    this.Parent.Init += new EventHandler(this.Parent_Init);
}
//the handler gets called, at this point we can cast the parent as a module base
//and load the configuration and resource file into the nested control
private void Parent_Init(object sender, System.EventArgs e)
{
    this.ModuleConfiguration = ((ModuleBase)this.Parent).ModuleConfiguration;
    this.LocalResourceFile = ((ModuleBase)this.Parent).LocalResourceFile;
}
Run Code Online (Sandbox Code Playgroud)

这意味着在Page_Load嵌套控件的情况下,它将已经拥有配置和本地资源文件。

这也意味着您不必在使用子控件的每个父控件上加载配置和本地资源文件。

当然,只有当父级的类型为 ModuleBase 时,这才有效

更具体地说,这适用于版本 7.00.06