Reputation: 22086
I have a asp.net webform application. Now I have to add master page in this application, but I don’t know how to merge or add new created master page with old webforms? How to handle html in webforms like <head>
, <body>
? Any link in this regard will be helpful.
Upvotes: 6
Views: 52269
Reputation: 11
you can add the content holder tag in master page. So when you add 'MasterPageFile="~/Site.Master"' then you able to add content of other pages.
Upvotes: 0
Reputation: 9242
1- Define the fixed elements in your design, and put them inside the newly created master page
2- Define the dynamic ones, and add asp:ContentPlaceHolder
for them ( most commonly one for HEAD
, one for main content in your BODY
, and one for side content "if applicable")
<asp:ContentPlaceHolder ID="CphHead" runat="server">
</asp:ContentPlaceHolder>
3- In your pages, add MasterPageFile="~/MASTER_PAGE_PATH"
inside the Page directive.
4- Add asp:Content
sections inside your pages which will hold the dynamic content in your pages, and don't forget to reference the correct ContentPlaceholder ID
.
<asp:Content ID="HeadContent" ContentPlaceHolderID="CphHead" runat="server">
// Your content goes here...
</asp:Content>
5- Copy your page content inside these asp:content
sections, and BOOOOM....you are done.
Upvotes: 6
Reputation: 405
at the top of the new page in the '<%@ page @>' tag add 'MasterPageFile="~/Site.Master"' then add the needed placeholders
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
of course modify these to the names you are using
Upvotes: 5