代码之家  ›  专栏  ›  技术社区  ›  roman m

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

  •  7
  • roman m  · 技术社区  · 17 年前

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

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

    2 回复  |  直到 9 年前
        1
  •  8
  •   roman m    17 年前

    威廉离职 DNN forum 为我回答了这个问题,我也会把答案贴在这里。

    由于子控件继承自PortalModuleBase,因此我将执行以下操作 父控件

    注意:假定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进行任何本地化。

        2
  •  3
  •   m.t.bennett    13 年前

    我可以在嵌套控件中这样做:

    //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 嵌套控件的事件,它将已经拥有配置和本地资源文件。

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

    更具体地说,这在7.00.06版中有效

    推荐文章