1

Master page:

<form runat="server">
<Scirra:MainMenu runat="server" ID="MainMenu" TopTabSelected="home" SubTabSelected="link2" />
<asp:ContentPlaceHolder id="MainContent" runat="server">
snip

Content page:

Master.MainMenu.TopTabSelected = "forum";

I know I'm probably doing this wrong, but is this possible? I want to change a parameter of that control. It says 'inaccessible due to protection level'.

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • [sorry, just saw the property in the markup, ignore previous] But still try `var mainmenu = Master.FindControl("MainMenu") as MainMenu; if(mainmenu!=null)mainmenu.TopTabSelected="forum";` – Brad Christie Mar 05 '11 at 23:29

2 Answers2

2

You should provide a public property f.e MenuTabSelected in your MasterPage that Gets/Sets this property of your Menu.

public string MenuTabSelected {
    get { return MainMenu.TopTabSelected; }
    set { MainMenu.TopTabSelected = value; }
}

Then you can access it in this way:

((YourMasterPage)Master).MenuTabSelected = "forum";

where YourMasterPage is the type of your MasterPage.

The compiler error is thrown because you want to access a private or protected control from outside of your MasterPage-Class. This would only be allowed if it would be public, what is not recommended. You have more control if you do it the way i suggested :)

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

find menu items in content page and change its value

protected void Page_Load(object sender, EventArgs e)
{


Menu mainMenu = (Menu)Page.Master.FindControl("NavigationMenu");

MenuItem menuMaterials = mainMenu.FindItem("Materials");

    if (menuMaterials.Value == "Materials")
    {
         menuMaterials.Value = "NO materials";
        menuMaterials.Text = "No materials";
    }

}   
Dipen
  • 1,056
  • 1
  • 19
  • 36