F.Bruno
F.Bruno

Reputation: 143

Commmon menu for multiple aspx pages

I've been working on a project and I noticed I reuse the same menu over and over again and it got to a point where, if I needed to change something I would need to change 20+ pages too because of it being a menu.

My question is, is it possible to have a single aspx file with the working menu on it, and have the other pages call it? So far I've tried

<?php include('Menu.aspx') ?> 

<iframe id="myIframe" src="Menu.aspx" height="100%" width="100%"></iframe>

The later (iframe) showed something but I was unable to resize it and the links didn't work either. The php one didn't show anything. Any help would be appreciated, thank you very much.

Upvotes: 0

Views: 540

Answers (4)

Mukesh Kumar
Mukesh Kumar

Reputation: 2376

There are two option to reuse menu in asp.net page.

  1. Master Page
  2. User Control

using sitemap and add into master page.

https://msdn.microsoft.com/en-us/library/aa581781.aspx

http://webproject.scottgu.com/CSharp/MasterPages/MasterPages.aspx

Hope this will help you. thanks

Upvotes: 0

Pikoh
Pikoh

Reputation: 7713

You have to make yourself familiar with master pages. See this as a beginner tutorial: http://www.codeproject.com/Articles/333650/Beginner-s-Tutorial-on-Master-Pages-in-ASP-NET

Upvotes: 0

Arghya C
Arghya C

Reputation: 10078

The best option for you is to create an User Control, and use it in all your pages.

An user control is similar to a server control (e.g. asp textbox, update panel etc.), but custom made by the developer to suit his specific needs.

If the menu is more like the common layout/theme of all your pages you can use a Master Page instead.

Upvotes: 1

Markus
Markus

Reputation: 22511

You can use the following approaches to solve this:

  • Master Pages allow to have a common layout that is applied to several aspx pages. The master page defines a layout and provides some content placeholders that are filled in by the pages that reference the master page. Your example of a menu fits good; the menu would be placed on the master page. See this link for details.
  • Another way to share layouts are ASP.NET UserControls. These are created as ascx files and can be reused in several aspx pages. See this link for details.

Upvotes: 2

Related Questions