开发者

ASP.net get content page to change master page control

Master page:

<form runat="server">
<Scirra:MainMenu runat="server" ID="MainMenu" TopTabSelected="home" SubTabSelecte开发者_如何学Cd="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'.


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 :)


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";
    }

}   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜