7

我正在为 DNN 5 编写一个自定义模块,并且我需要在模块中的每个控件上都有一个“管理”链接。我创建了一个继承自 PortalModuleBase 的新用户控件(“ManagerLink”),将我的链接放入该控件,然后将该控件放在我的所有主要控件上。

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

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

  2. 是否有获取 ModuleId 的替代方法(等效于 PortalSettings.ActiveTab.TabID)

2014 年更新:

刚刚看到另一个比原来更好的答案(并接受了它)。

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

4

2 回答 2

8

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

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

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

VB.NET:

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

以上内容允许子控件使用父控件的 ModuleConfiguration(将包括 ModuleId)和 LocalResourceFile 进行任何本地化。

于 2009-03-16T09:58:26.903 回答
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;
}

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

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

当然,这仅在父级为 ModuleBase 类型时才有效

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

于 2013-05-27T01:26:49.440 回答