Search code examples
c#dotnetnukeddrmenu

DotNetNuke DDRMenu set NodeSelector in code behind


I'm using DDRMenu in DotNetNuke to select a menu node from my site structure and display only a subnode in a specific navigation in my template

<%@ Register TagPrefix="dnn" TagName="MENU" Src="~/DesktopModules/DDRMenu/Menu.ascx" %>
<dnn:MENU ID="MenuFooter" MenuStyle="MenuFooter" IncludeHidden="true" NodeSelector="FooterNavigation,0,1" runat="server" ></dnn:MENU>

Now I want to be able to set the NodeSelector attribute in the code behind file, because I want to be able to dynamically set the value on Page_Load

// load footer navigation node from a config file
protected void Page_Load(object sender, EventArgs e)
{
     var footerNode = Config.Instance.Navigation.FooterNode;
     MenuFooter.NodeSelector = footerNode + ",0,1";
}

But this doesn't work, as there is no NodeSelector attribute on System.Web.UI.UserControl.

Error 'System.Web.UI.UserControl' does not contain a definition for 'NodeSelector' and no extension method 'NodeSelector' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) C:\Projects\eWolf2012\dev\DNN\Portals_default\Skins\JWEwolfSkin2012\Simple.ascx.cs 141 24 JWEwolfSkin2012

Is there any way to achieve this?

Kind regards


Solution

  • Usually the Menu.ascx in DDRMenu inherits from the DDRMenu SkinObject:

    <%@ Control Language="C#" AutoEventWireup="false" EnableViewState="false" Inherits="DotNetNuke.Web.DDRMenu.SkinObject" %>
    

    Since you are talking about changing the code behind I guess that you are using a custom control that embeds the Menu.ascx. In which case you should be able to access the NodeSelector property since it exists in the SkinObject class.

    What I am suspecting is happening is that your control type is not loaded correctly by the designer, and that it falls back on the UserControl type which doesn't have the NodeSelector property.

    Try the following:

    • Include the DDRMenu assembly in your current project (because it won't load the type if it doesn't find the assembly), then rewrite the include to kick the designer into motion. I'm pretty confident this is the cause of the problem, but if not:
    • Fiddle with your src attribute and check in the *.designer file what type is defined.
    • Define it manually in your code-behind file instead of letting the designer do it.