Hi William,
Thank you for your hints - they helped to get the code working. (That was a long day here yesterday and I missed to "dig out" TabController and ModuleController classes, and also mixed up ModuleDefinitionInfo with ModuleInfo). Yes, I do investigate DNN API by running my sample site under debugger. I must say I had expected such methods would have been already there in DNN core, and I had also expected that TabController and ModuleController could have had static methods to find ID of certain Tab or Module within a tab given TabName and ModuleName...
Anyway, the code is working now. And I'm happy :)
Here is this code:
/// <summary>
/// Navigates to current module own view control
/// given this control's key <paramref name="controlKey"/>
/// </summary>
/// <param name="currentModuleInstance">Current module instance,
/// see <see cref="PortalModuleBase"/></param>
/// <param name="controlKey">A key of view control to navigate to</param>
public void NavigateToCurrentModuleViewControl(
PortalModuleBase currentModuleInstance,
string controlKey)
{
int tabId = currentModuleInstance.TabId; ;
string thisModuleIdAsAdditionalParameter =
string.format("mid={0}", this.ModuleId);
currentModuleInstance.Page.Response.Redirect(
DotNetNuke.Common.Globals.NavigateURL(
tabId,
controlKey,
thisModuleIdAsAdditionalParameter));
}
/// <summary>
/// Gets TabId by its tab-/page-name
/// </summary>
/// <param name="portalId">Portal Id</param>
/// <param name="tabName">Tab Name</param>
/// <returns>TabId if tabName belongs to an exiting page, -1 otherwise</returns>
/// <remarks>
/// 1. This method skips hidden pages.
/// </remarks>
public int GetTabIdByTabName(int portalId, string tabName)
{
DotNetNuke.Entities.Tabs.TabInfo tabInfo =
(new DotNetNuke.Entities.Tabs.TabController()).
GetTabByName(tabName, portalId);
if (tabInfo != null) return tabInfo.TabID;
throw new ApplicationException(
string.format("Can't get TabId for given Portalid={0} and TabName='{1}'", portalId, tabName));
}
/// <summary>
/// Gets ModuleId by module name
/// </summary>
/// <param name="tabId">Tab Id</param>
/// <param name="moduleName">Module name</param>
/// <returns>ModuleId if given module name corresponds to an
/// installed module, throws <see cref="ApplicationException"/>
/// otherwsie.
/// </returns>
public int GetModuleIdByName(int tabId, string moduleName)
{
DotNetNuke.Entities.Modules.ModuleController moduleController =
new ModuleController();
Dictionary<int, ModuleInfo> tabModules =
(new DotNetNuke.Entities.Modules.ModuleController()).
GetTabModules(tabId);
foreach (ModuleInfo moduleInfo in tabModules.Values)
if (string.Compare(moduleInfo.ModuleName, moduleName, true) == 0)
return moduleInfo.ModuleID;
throw new ApplicationException
(string.format("Can't get ModuleId for given module name '{0}'",
moduleName));
}
/// <summary>
/// Navigates to other tab's module view control
/// given <paramref name="tabName"/>, <paramref name="moduleName"/> and
/// target control's <paramref name="controlKey"/>
/// </summary>
/// <param name="currentModuleInstance">Current module instance,
/// see <see cref="PortalModuleBase"/></param>
/// <param name="tabName">Tab Name</param>
/// <param name="moduleName">Module Name</param>
/// <param name="controlKey">A key of view control to navigate to</param>
public void NavigateToOtherTabModuleViewControl(
PortalModuleBase currentModuleInstance,
string tabName,
string moduleName,
string controlKey)
{
int portalId = currentModuleInstance.PortalId;
int tabId = GetTabIdByTabName(portalId, tabName);
int moduleId = GetModuleIdByName(tabId, moduleName);
string moduleIdAsAdditionalParameter =
string.format("mid={0}", moduleId);
currentModuleInstance.Page.Response.Redirect(
DotNetNuke.Common.Globals.NavigateURL(
tabId,
controlKey,
moduleIdAsAdditionalParameter), true);
}
Intended usage of the above code:
string tabName = "Test";
string moduleName = "YourCompany.TestModule";
string controlKey = "DetailedInfoViewControl";
NavigateToOtherTabModuleViewControl(this, tabName, moduleName, controlKey);
Thank you.
--Shamil