问题描述
我是 DotNetNuke 新手.请温柔点.我正在使用DotNetNuke 6 Compiled Module"模板来构建我的模块.我在项目中已经有 View.ascx 控件,并添加了另一个名为 test.ascx 的控件.
I'm a DotNetNuke newbie. Please be gentle. I'm using the "DotNetNuke 6 Compiled Module" template to build my module. I already have View.ascx control in the project and have added another control called test.ascx.
我的问题是:如何在添加模块的不同页面中显示不同的视图.(如果这可能的话)例如在说 default.aspx 页面上显示 View.ascx,然后在 default2.aspx 页面上显示 test.ascx 用户控件?
My question is: how do I show different different views in different pages I add the module to. (if that is possible at all) e.g Show View.ascx on say the default.aspx page and then on the default2.aspx page show the test.ascx user control?
如果这是不可能的,是否意味着每个 ascx 控件都需要不同的 Visual Studio 项目.肯定不会.
If this is not possible does it mean I need different visual studio projects for each ascx control. Surely not.
推荐答案
Astro,
选项 1:
您需要转到主机 > 扩展 > 编辑您的扩展 > 扩展模块定义,然后单击添加控件.
You need to go to Host > Extensions > Edit your extesion > Expand Module definition and click on add control.
在这里您必须选择您的 ascx 控件并提供任何字符串形式的键.假设您提供了密钥 test
,您选择了用户控件并将控件类型选择为 view
并保存了它.
Here you have to select your ascx control and provide key as any string. Let's say you provided key test
, you selected user control and selected control type as view
and saved it.
现在从视图中,您可以使用以下代码导航到新添加的控件:DotNetNuke.Common.Globals.NavigateUrl(TabId,"test","mid="+ModuleID);
Now from view you can use following code to navigate to the newly added control:
DotNetNuke.Common.Globals.NavigateUrl(TabId,"test","mid="+ModuleID);
这将重定向页面并使用 test.ascx 加载您的页面.
This will redirect the page and load your page with test.ascx.
当您想要默认显示 view.ascx 并且想要在执行某些操作时切换视图并显示 test.ascx 时,您可以使用这种选项.这里的缺点是,当您切换到 test.ascx 时,添加到页面的所有其他模块都将不可见.
You can use this kind of option when you want to show view.ascx by default and want to switch view when on some action and show test.ascx. Disadvantage here is, when you switch to test.ascx, all other modules added to page will not be visible.
选项 2:
您必须在模块中创建一个新定义.为此,请转到主机 > 扩展 > 编辑您的模块 > 扩展模块定义 > 单击添加并添加新定义.添加定义后,您可以将 test.ascx 和视图控件添加到定义中,无需任何键.
You have to create a new definition in module. For that go to Host > Extensions > Edit Your module > Expand Module Definitoins > Click on add and add new definition. Once definition is added, you can add your test.ascx and view control to the definition without any key.
完成上述操作后,如果您再次删除模块并将其添加到页面,则会显示页面中添加的两个模块.这是两个定义.以博客模块定义为例,了解多重定义的工作原理.
Once above is done, if you delete and add your module to page again, it will show two modules added in the page. These are two definitions. Look at the blog module definition for example of how multiple definitions works.
当您想同时显示来自同一模块的多个视图控件时使用此选项.
This option is used when you want to show multiple view control at the same time from the same module.
我希望这会有所帮助.如果您还有其他问题,请告诉我.
I hope this helps. Let me know if you have any more questions.
这篇关于DNN:在一个模块中使用多个 Web 用户控件并在不同页面中显示不同的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!