Add ASP.NET Masterpage Afterwards

When you’ve got some existing ASP.NET pages and you later on want to add a common masterpage, do this:

Master Page

  1. Create a masterpage, e.g. Management.Master.
  2. Add the sub pages’ comon controls to the master.
  3. In the Management.Master, add ContentPlaceHolder items for head and body:


Sub Page

Do the following in the subpage.aspx:

  1. Add masterpagefile to page level directive:
    <%@ Page ... MasterPageFile="Management.Master"
  2. Remove the , ,
    and

    , tags.

  3. Replace the tag by the tag respecting the link to the ContentPlaceHolder via ID and ContentPlaceHolderID, like this:

    // former head content goes here

  1. Likewise replace the body tag by the tag:

    // former body content goes here

Sub Page Easy

If you've got nothing than the </code> tag inside of the <code><head></code> section, it is a bit easier:</p> <ol> <li>Add masterpagefile and title to page level directive:<br /> <code><%@ Page ... MasterPageFile="Management.Master" Title="Subpage"</code> </li> <li>Remove the <code><head></code> section.</li> <li>Replace the <code><body></code> tag by the <code><asp:Content...></code> tag respecting the link to the ContentPlaceHolder via ID and ContentPlaceHolderID, like this:</li> </ol> <pre><code><asp:Content ID="Cont1" ContentPlaceHolderID="CphBody" runat="server"> // former body content goes here </asp:Content> </code></pre> <p><em>Finish</em></p> </div><!-- .entry-content --> <footer class="entry-meta"> This entry was posted in <a href="https://99-developer-tools.com/category/tools/" rel="category tag">Tools</a> and tagged <a href="https://99-developer-tools.com/tag/asp-net/" rel="tag">ASP.NET</a> by <a href="https://99-developer-tools.com/author/andreaswww/">admin</a>. Bookmark the <a href="https://99-developer-tools.com/add-asp-net-masterpage-afterwards/" title="Permalink to Add ASP.NET Masterpage Afterwards" rel="bookmark">permalink</a>. </footer><!-- .entry-meta --> </article><!-- #post-1985 --> <div id="comments"> </div><!-- #comments --> </div><!-- #content --> </div><!-- #primary --> </div><!-- #main --> <footer id="colophon"> <div id="site-generator"> <a href="https://wordpress.org/" class="imprint" title="Semantic Personal Publishing Platform"> Proudly powered by WordPress </a> </div> </footer><!-- #colophon --> </div><!-- #page --> <script type="text/javascript" src="https://99-developer-tools.com/wp-includes/js/comment-reply.min.js?ver=6.5.5" id="comment-reply-js" async="async" data-wp-strategy="async"></script> </body> </html>