質問

I'm writing a website in Visual Studio Web Developer 2010 (Express edition). I have created a Master file which my content is styled with.

I want to put a right hand menu in my master file, but from the actual website pages, I want to say whether it should show particular menu items. For example, the home page would have a certain set of menu items on the right where as the contact page might have another set.

Should I set it up so that the master file handles true or false as to whether to show certain menu items (default all to false)... or should I handle this from the content pages? ie: call menu functions to draw from there?

役に立ちましたか?

解決

You can add a master page declaration to the page, so that you can access it programmatically like so:

<%@ MasterType  virtualPath="~/MasterPage.master"%>

Put that right under the Page tag on the page you want to enable or disable access from.

Then, in your code behind, you can access the master page methods, one of which can be a method to enable or disable that side menu.

Something like:

Master.MyEnableMenuMethod();

Additionally, you can add that Master Page declaration dynamically, like so:

void Page_PreInit(Object sender, EventArgs e)
{
    this.MasterPageFile = "~/MasterPage.master";
}

See http://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.85).aspx for more.

他のヒント

The way I've done this sort of thing is by putting some code withing the menu markup as so:

<% if(!HttpContext.Request.Path.Contains("Contact.aspx")) { %>
   <li> <a href="Contact.aspx">Contacts</a></li>
<%}%}>

And so on...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top