开发者

With ASP .NET, how do I display a side submenu depending on what user picked from the main menu?

I come from PHP side, but I'm in need to develop a site using ASP .NET

So far I manage to create a master page. Now I'm dealing with menus and submenus

What I'm trying to do is, if the user picks "About Us" from the main menu, under the about us page I want to display a submenu with the options "who we are, what we do, contact us"

If the user picks "Our Products" from the main menu, then under the products page I want to display a submenu with the options "product 1, product 2, product 3"

开发者_StackOverflow社区Is this possible with only one master page?

I read something about menu control but not sure that is what I need. So far I found how to display a sitemap, but not specific sections of a sitemap, if this is the way to do things.

Any links, sample code, point of reference will be appreciated.

Thanks


One approach I'd look at is using JavaScript to display the selected menu items without a postback.

I'd need more information on how your main menu is hooked up though.


You should probably write a separate web User Control to handle the menu and just include it in your Master page as usual.

A simple way is to use a Placeholder control in side which you write the markup for each menu set you want to include. Set their Visible property to false in the markup (.ascx file).

<asp:Placeholder runat='server' id='phAbout' Visible='false'>
<a href='/about/index.aspx'>Information about Us</a>
<a href='/about/us.aspx'>About Us</a>
</asp:Placeholder />

Then, at Page_Load time, do some processing, for exampl examine the Request.Path property to work out what sub-directory the current page is in etc. Then run a bit of logic to show the relevant menus by setting the associated Placeholder's Visible property to true.


It looks like each of your main menu item contains a group of pages.

Create a sitemap file to describe the whole site and all menus. And while each page is loading, site map gives you the current node from the map, which is the current page.

You can easily construct the submenus by walking through the nodes in any page/master page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜