tags:

views:

36

answers:

1

I got a requirement to create a dynamic menus using extern function so, we can consume it anywhere, following is the complete requirement :

Please create a dynamic horizontal link menu in the top of the Master Page. This will be the menu that is displayed on every page. We need to be able to set the links on this page from the code behind. The information we want to set is the link text, and the link path (href). The idea behind this is that based on who is logged into the application, and what page they are on, there will be different link possibilities. We should make this code reusable. The procedure to actually lay out the links would look something like this:

public static extern void SetDynamicLinks(Control ContainingControl, string[] arLinkTitles, string[] arLinks) { …code… }

We would call a procedure from the Page_Load of the Master Page that would decide what links we need to display. This procedure would be application dependant. This procedure would then call the "SetDynamicLinks" procedure mentioned above passing it the required parameters to make the correct links in the passed container control.

Any help for above, will be most appreciated. Thanks in advance.

+1  A: 

I don't see what the codeline has to do with this but to "talk" from page to masterpage can be done like this:

create an interface to access the properties in the master you need

public interface IMenuMaster
{
    Menu MainMenu { get; }
}

implement the interface in the masterpage

public partial class MasterPage : System.Web.UI.MasterPage , IMenuMaster
{
    public Menu MainMenu
    {
        get { return Menu1; } where menu1 is the menu you want to expose
    }
}

use it like this

protected void Page_Load(object sender, EventArgs e)
{
    IMenuMaster m = Master as IMenuMaster;
    if (m != null)
    {
       //call whatever you want here and access the menu like this
       m.MainMenu........
    }
}
Caspar Kleijne
@Caspar - Thanks a lot for your solution. yes, you are right this is one of the solution, implemented with Master page. But I need a customized method like : SetDynamicLinks(Control ContainingControl, string[] arLinkTitles, string[] arLinks) - in this method the menus should be written on a specified control and the return type of this method is void. Could you give me some clue?
Rick