Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Navigating to a module on different page...Navigating to a module on different page...
Previous
 
Next
New Post
10/25/2009 4:29 PM
 

Hi All,

I'm looking for a code snippet to be used to navigate to a module on different page, I assume that:

- {{PageName}} to navigate is given but its TabId is not;

- {{ModuleNameToNaviagate}} is given but its ModuleId is not;

- {{ControlKeyToNavigate}} is given;

- there is just one module on target page.

I can use code snippet as published here:

http://adefwebserver.com/dotnetnukehelp/NavigateURL/Default.htm

but I still to find out how to get TabId by PageName, and ModuleId by ModuleName. Could you please advise?

Thank you.

--Shamil

 
New Post
10/25/2009 8:01 PM
 

Never mind - I figured it out (please correct/polish/optimize code if needed):

        /// <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)
        {
            int tabId = -1;
            //?tabId = DotNetNuke.Entities.Tabs.TabController.GetTabByTabPath(portalId, tabName);
            List<DotNetNuke.Entities.Tabs.TabInfo> tabs = DotNetNuke.Entities.Tabs.TabController.GetPortalTabs(portalId, -1, false, false);
            foreach (DotNetNuke.Entities.Tabs.TabInfo tabInfo in tabs)
                if (string.Compare(tabInfo.TabName, tabName, true) == 0)
                    return tabInfo.TabID;
            return tabId;
        }

        /// <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));
        }

 

Thank you.

--Shamil

 

 
New Post
10/25/2009 8:53 PM
 

Sorry, it didn't work - still can't navigate to a page with given name to have its certain module opened a certain (view) control. It is probably not possible at all? Please advise - below are code snippets, which almost work as required:

/// <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)
{
    int tabId = -1;
    //?tabId = DotNetNuke.Entities.Tabs.TabController.GetTabByTabPath(portalId, tabName);
    List<DotNetNuke.Entities.Tabs.TabInfo> tabs = DotNetNuke.Entities.Tabs.TabController.GetPortalTabs(portalId, -1, false, false);
    foreach (DotNetNuke.Entities.Tabs.TabInfo tabInfo in tabs)
        if (string.Compare(tabInfo.TabName, tabName, true) == 0)
            return tabInfo.TabID;
    return tabId;
}

/// <summary>
/// Gets ModuleId by module friednly name
/// </summary>
/// <param name="moduleFriendlyName">Module Friendly name</param>
/// <returns>ModuleId if given module friendly name corresponds to an
/// installed module, throws <see cref="ApplicationException"/>
/// otherwsie.
/// </returns>
public int GetModuleIdByFriendlyName(string moduleFriendlyName)
{
    //?DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionInfo info =
    //  DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionController.GetModuleDefinitionByFriendlyName
    //    (moduleFriendlyName);
    Dictionary<int, DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionInfo> dictionary =
      DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionController.GetModuleDefinitions();

    foreach (DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionInfo info in dictionary.Values)
        if (string.Compare(info.FriendlyName, moduleFriendlyName, true) == 0)
            return info.DesktopModuleID;
   
    throw new ApplicationException
        (string.format("Can't get ModuleId for given module friednly name '{0}'",
          moduleFriendlyName));
}

/// <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 NavigateToOtherTabModuleViewControl(
    PortalModuleBase currentModuleInstance,
    string tabName,
    string moduleFriendlyName,
    string controlKey)
{
    int portalId = this.PortalId;
    int tabId = GetTabIdByTabName(portalId, tabName);
    int moduleId = GetModuleIdByFriendlyName(moduleFriendlyName);

    string moduleIdAsAdditionalParameter =
            string.format("mid={0}", moduleId);
    // it doesn't work -
    // currentModuleInstance.Page.Response.Redirect(
    //    DotNetNuke.Common.Globals.NavigateURL(
    //     tabId,
    //     controlKey,
    //     moduleIdAsAdditionalParameter), true);
    currentModuleInstance.Page.Response.Redirect(
        DotNetNuke.Common.Globals.NavigateURL(
         tabId), true);
}

Thank you.

--Shamil

 

 

 
New Post
10/25/2009 9:02 PM
 

FYI: Expected usage of the prev. posting code:

1. Doesn't work - Navigate to the other page module with given (view) control displayed:

        string tabName = "TestPage";
        string moduleFiendlyName = "TestModule";
        string controlKey = "DetailedView";

        NavigateToOtherTabModuleViewControl(this, tabName, moduleFiendlyName, controlKey); 

2. Works OK: Navigate to a view control of the current module having multiple view controls

            NavigateToCurrentModuleViewControl(this, "DetailedView");
 

3. Works by definition: Navigate to the default (switchboard) view control of the current module - just to have complete minimal set of navigation methods to implement module views' switchboard):

               this.Page.Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(), true);
 

Thank you.

--Shamil

 
New Post
10/25/2009 11:45 PM
 

You're getting close to a solution . . .

I would suggest you set debugger breakpoints to examin the value of TabID and ModuleID returned from your two functions and compare with expected values.

It would appear that your function to return the TabID from TabName should work correctly. However, a more efficient approach would be to use the TabController.GetTabByName method.

However, your function to obtain the ModuleID from module friendly name is failing because it is returning the DesktopModuleID not the ModuleID. I would use ModuleController.GetTabModules to obtain the dictionary of ModuleInfo objects for the given TabID then iterate through the ModuleInfo objects to locate the desired ModuleName (not FriendlyName which can be changed by the host user). Note that if you are programming against DNN 5.x, you would use the newly added DesktopModule.ModuleName property of the ModuleInfo object.

Hope this helps!

The call to NavigateURL should return the proper URL for the Redirect provided that the TabID and ModuleID are correctly supplied.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Navigating to a module on different page...Navigating to a module on different page...


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out