0

We are new to DNN and we plan to add a product module that is in charge of adding, editing, deleting, listing, and showing the details of the products.

We have written a UserControl named ProductsList.ascx, which has AddProducts.ascx and ShowPrdoctDetail.ascx defined in it, using Host => Extensions => ProductsList => Module Definition => Add Module Control.

In admin mode,we have created a page and dragged the module in it, so that the admin of the site can add, edit, delete, and see the details of each product.

Also there is a slideshow in the homepage that shows the latest products.In addition, the products are shown in the menu.

Now, we want to redirect user to the product detail page (ShowPrdoctDetail.ascx in our case) whenever he/she clicked the product shown in slideshow or in menu.

We are aware of Globals.NavigateUrl() method, but it needs tabid and mid to redirect to a specific page and module and in DNN every added page by admin will get different tabid and mid.

Since in DNN, admin can create many pages and add this module to them, we have no idea that what tabid and mid we should pass to Globals.NavigateUrl() in order to navigate user to product details page (ShowPrdoctDetail.ascx) when user clicked on a specific product in menu or slideshow.

Any kind of help is highly appreciated.

2 Answers2

0

Try save current tabid to DB when adding product detail module into page. And with ProductId, you can grab tabid of product detail, and use it to redirect to correct page.

erw13n
  • 474
  • 5
  • 12
0

The way I would tackle this is to create another Module Definition for the details module and give it a Friendly name like "Product Details" and add the ShowProductDetail.ascx module control as the default view of this new module definition.

Then you can drag that new module onto a page for your product details page.

In your main Product Admin module, you can create a setting view with a dropdown list that contains a list of all tabs (pages) that the "Product Details" module on.

You can use the following method to get the list of tabs in the portal that has an instance of the module:

private List<TabInfo> GetAllModuleTabsbyModuleName(string friendlyName)
{
    List<TabInfo> results = new List<TabInfo>();
    Dictionary<int, int> dups = new Dictionary<int, int>();

    ModuleController mc = new ModuleController();
    ArrayList oModules = mc.GetModulesByDefinition(base.PortalId, friendlyName);

    TabController tc = new TabController();
    TabCollection oTabs = tc.GetTabsByPortal(base.PortalId);

    foreach (ModuleInfo oModule in oModules)
    {
        foreach (KeyValuePair<int, TabInfo> oTab in oTabs)
        {
            if (oTab.Key == oModule.TabID && !dups.ContainsKey(oModule.TabID))
            {
                results.Add(oTab.Value);
                dups.Add(oModule.TabID, oModule.TabID);
            }
        }
    }
    return results;
}  

You can bind that to the dropdown list options and an administrator could select the page that will be redirected when a product is clicked on the main module.

ddlProdDetailsTab.DataSource = GetAllModuleTabsbyModuleName("Product Details");
ddlProdDetailsTab.DataValueField = "TabID";
ddlProdDetailsTab.DataTextField = "TabName";
ddlProdDetailsTab.DataBind();

So from the settings, you know the TabId you want to redirect to, then you need the moduleId and you can create the redirect using NavigateUrl().

var pdTab = TabController.Instance.GetTab(Convert.ToInt32(Settings["ProductDetailTabId"]), PortalId);
var pdModule = pdTab.Modules.Cast<ModuleInfo>().FirstOrDefault(m => m.ModuleName == "Product Details");
var productLink = Globals.NavigateURL(pdTab.TabId, "", "mid=" + pdModule.ModuleId, "productId=" + productId);
Fix It Scotty
  • 2,852
  • 11
  • 12