开发者

ASP.NET master page - control if menu html is shown or not

I'm creating an ASP.NET site where some pages need to have a div floated to the left with the site menu in and other pages don't have the menu div and instead the content takes up the entire page width.

I'm planning to use master pages - I was wond开发者_StackOverflowering how best to achieve this - a few immediate thoughts spring to mind:

  • Create 2 master pages, one with menu and one without. When creating content pages choose which master to inherit from. This is straightforward, but may require more rework if the site design changes
  • Create a single master page with a content placeholder for the menu. On each page include a menu div only if it is needed (seems more messy this approach)
  • Nested master pages?

It seems like this may be a common problem, so interested in how this is normally addressed. Note I am questioning the need for having pages without the menu - it would be simpler if all pages had exactly the same structure.


Nested master pages is probably the standard answer and should work well.

An alternative approach that occurs to me would be to put your menu in a panel control on the master page and expose a property that lets you toggle the visibility of the panel. I have not tried this yet, so I am not sure how practical it is, but it might be a fun concept to play with. If it works the way I expect this gives you a single master page that can be reconfigured by the content page.


It's up to personal preferences, but the way I was recommended was to create nested master pages, the first master page would not contain the menu but the 2nd one would and then just point to one of the master pages.


Nested Master pages should solve your problem and also keep the Web Site scalable.


At my previous company we used two separate master pages for a similar scenario. One that included the menu and one that did not. And because they both inherited the same base master page, they both had the same functionality.

But then again, I think it comes down to personal preference.

Personally, I like the idea of having two separate pages as that way it's a bit easier to see what's going on, compared to the nested master pages.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜